Hi Valentin, I think you might be wrong. Only the autoboxed Wrapper Objects for Boolean(true,false), Byte, Character('\u0000' -> '\u--7f', Short( -128 -> 127) Integer( -128 -> 127) Long( -128 -> 127) are pooled. However the Float and Double are not pooled.
But when you create Objects using the new() then they are never pooled as the same as Strings.
"==" returns false and equals() method returns true;
"==" always compares the references and here i1 and i2 are two different references so the result is "false"
By default, equals() method also compares the references not the state of the objects.But if the equals() method is overriden in the compared classes then the method compares the states of the objects. Integer class has the equals() method overridden in it.That's why the equals() method in this case compares the states of the i1 and i2, which is same, So the result is "true".
I hope it clears..
Joined: Feb 15, 2006
I didn't test yet but in the K&B book it said that I said above... I'll read one more time this evening