On Jul 19, 2007, at 01:10, Andreas L Delmelle wrote:

<snip />
  Number oneInt = new Integer(1);
  Number oneDouble = new Double(1.0);
  boolean check = (oneInt.hashCode() != oneDouble.hashCode());

=> (check == true)

Can this be relied upon?

AFAICT, it can.
Integer.hashCode() will simply return the int value, while Double.hashCode() uses Double.doubleToLongBits(), which should always produce different results, even if the numeric value is the same.

The used implementations for equals(), I would presume to be safe: we can count on the fact that

Integer oneInt = new Integer(1);
check = (oneInt.equals(new Double(1)));

check will always be false here.

FTM, I have committed the change using the Number-subclass hashCode() implementations.


Cheers

Andreas

Reply via email to