Hi Sumit David,
Line 1 above returns true. Does that mean new Integer("2") in line 2 points to the same object as in line 1?
No. The object created at line 1 and the object created at line 2 are TWO different objects. Their references are not equal.
However the equals method of Integer returns true, because the *contents* of these two distinct objects is the same. Object.equals() compares references. Integer overrides equals(). Integer.equals() compares contents.
new Integer(�2�) == new Integer(�2�) is false.
new Integer(�2�).equals(new Integer(�2)) is true.
Does it prove that primitive wrapper classes are immutable?
containsKey returns true because the objects are equals() according to Integer.equals(). The Map interface specifies that containsKey uses the equals() method.
I am not sure how to prove the wrapper classes are immutable.
[ February 06, 2004: Message edited by: Marlene Miller ]