Hi All,
Another example taken from
http://devesh2k1.googlepages.com/home ===================================================================
Float f1 = new Float(Float.NaN);
Float f2 = new Float(Float.NaN);
System.out.println(f1 == f2); //Line 1 - Prints false
System.out.println(f1.equals(f2)); //Line 2 - Prints true
System.out.println(Float.NaN == Float.NaN); //Line 3 - Prints false
Float f3 = 0.0f;
Float f4 = -0.0f;
System.out.println(f3.equals(f4)); //Line 4 -Prints false
System.out.println(-0.0f == 0.0f); //Line 5 -Prints true
I understand that Line 1 prints false as f1 and f2 are two different objects. Line 2 is true as the contents of the objects are the same, hence true.
I am unsure of why Line 3 is false, please can someone explain?
Line 4 is false as the contents of each object are different.
Line 5 is true as this is an exceptional case stated by the javadoc.
Thanks