Ewww that is tricky! We know that Double.NaN == Double.NaN as a comparison of double values returns false, so naturally we expect the equals method to fail too.
Unfortunately, the Double equals method is:
public boolean equals(Object obj) {
return (obj != null)
&& (obj instanceof Double)
&& (doubleToLongBits(((Double)obj).value) ==
doubleToLongBits(value));
}
which instead of comparing double == double uses the doubleToLongBits conversion so the == ends up comparing the bit
patterns - which are equal. This unexpected result IS cited in the Javadocs.
Bill
------------------
author of: