Possible Duplicate:
Weird Java Boxing
Recently while I was reading about wrapper classes I came through this strange case:
Integer i1 = 1000;
Integer i2 = 1000;
if(i1 != i2) System.out.println("different objects");
if(i1 == i2) System.out.println("same object");
Which prints:
different objects
and
Integer i1 = 10;
Integer i2 = 10;
if(i1 != i2) System.out.println("different objects");
if(i1 == i2) System.out.println("same object");
Which prints:
same object
Is there any reasonable explanation for this case?
Thanks