Originally posted by karnatam narendraprasad:
public class Boxing {
public static void main(String args[]) {
Integer i1 = new Integer(10);
Integer i2 = 10;
System.out.println("Lessthan: " + (i1 <= i2));
System.out.println("Greaterthan: " + (i1 >= i2));
System.out.println("Equality: " + (i1 == i2));
}
}
it compiles fine.and give output as
Lessthan: true
Greaterthan: true
Equality: false
why they are not equal...
When == is applied to two object references, then what is being tested is whether those two references point to the same object.
The first reference refers to a new Integer. The second refers to an Integer object created from boxing.
Unless one of the operands is a primitive in ==, then unboxing will not occur.