Hi,
I think == method can be used in Primitive datatypes and not objects.
The moment it becomes Double and not double it becomes an object and plus
NaN is a static value. Since you initialized to both the objects to a constant value it evaluates to true. Replace this with Double.NaN with 1.0
it will evaluate to the same result.
Originally posted by Marcos Vilela:
1: Double a = new Double(Double.NaN);
2: Double b = new Double(Double.NaN);
3:
4: if( Double.NaN == Double.NaN )
5: System.out.println("True");
6: else
7: System.out.println("False");
8:
9: if( a.equals(b) )
10: System.out.println("True");
11: else
12: System.out.println("False");
ok the first expression is false. But why the second one is true if the equals() compare the Double Value?