Originally posted by lalitha kaparapu: But from JDK1.5, using AUTOBOXING, we can use wrapper objects just like primitive datatypes.
The same piece of code when compiled in jdk1.5 should produce the output as "Objects are equal!".[/QB]
Autoboxing only takes effect in expressions where you need a primitive but you only have a wrapper object, or vice versa. However, in the case of (iObj1 == iObj2), you don't need primitives to make the expression valid, so Java simply goes ahead with the usual object reference comparisons. (Remember, one important consideration in the design of Java 1.5 was backward compatibility. The behavior of old programs that use similar Integer object reference comparisons should not change just because you're now running them on a Java 1.5 JVM.)
However, if you change your expression to (iObj1 == (int)iObj2), then autoboxing will kick in--and it'll evaluate to true, as expected. [ November 07, 2007: Message edited by: Kelvin Lim ]