class D {
public static void main(String args[]) {
Integer b2=128;
Integer b3=128;
System.out.println(b2==b3);
}
}
Autoboxing caches -128 to 127. This is specified in the JLS (5.1.7).
If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.
A simple rule to remember when dealing with objects is - use .equals
if you want to check if the two objects are "equal", use ==
when you want to see if they point to the same instance.