int mm1 = -129; Integer mm2 = -129; System.out.println(mm1 == mm2); // TRUE } } I know that certain primitives are always to be boxed into the same immutable wrapper objects. These objects are then CACHED and REUSED, with the expectation that these are commonly used objects. These special values are:The short and int values between -128 and 127.
Can you explain the part of code in Bold since they are out of range and give different outputs.
This is what the Java Language Specification says.
If the operands of an equality operator are both of numeric type, or one is of numeric type and the other is convertible (�5.1.8) to numeric type, binary numeric promotion is performed on the operands (�5.6.2). If the promoted type of the operands is int or long, then an integer equality test is performed; if the promoted type is float or double, then a floating-point equality test is performed.
So when one operand is an int and the other is an Integer, the Integer is unboxed and the comparison is performed.