3 ms·
> But while going through the docs I stumbled upon this Gem You make it sound like that's crazy or something but the goal of .compare is to be used as a "compa
by saurik 5y ago
> But while going through the docs I stumbled upon this Gem
You make it sound like that's crazy or something but the goal of .compare is to be used as a "comparator" to provide an ordering of all possible values in the implementation of various data structures or sorting algorithms, while the goal of the various operators is to support programmatic logic.
- cuteboy19 5y agoWe need a little bit of background for this. In Java the == operator checks if two variables are pointing to the same object. The .equals() method checks for actual value equality. new String("Hi")==new String("Hi"); // False new String("Hi").equals(new String("Hi")); // True Except for primitives like ints and floats where == does value comparison. 1==1;// True For NaN the value comparison is false. Even then .equals returns true Float.NaN==Float.NaN; // False new Float(0f/0f).equals(new Float(0f/0f)); // True!!!