The Integer autobox cache (-128..127)
Autoboxing small int literals into Integer reuses cached instances for the range -128..127 (per the JLS,
implementations may cache more but must cache at least this range). Outside that range, each boxing creates
a new object, so == on boxed integers becomes an identity check that silently passes for small numbers and
silently fails for larger ones — a real, recurring bug source when someone compares Integer with ==
instead of .equals().
Integer i1 = 127, i2 = 127;
Integer i3 = 128, i4 = 128;
System.out.println("127 == 127 (boxed, cached): " + (i1 == i2));
System.out.println("128 == 128 (boxed, NOT cached): " + (i3 == i4));
System.out.println("128.equals(128): " + i3.equals(i4));