I just had to prove this - seeing is believing so they say:
public class test
{
public static void main(String[] args) throws Exception
{
final Integer intValue2 = 2;
Integer intValue = Integer.valueOf("2");
System.out.println("INFO: intValue2 = " + intValue2);
System.out.println("INFO: intValue = " + intValue);
if (intValue2 == intValue)
System.out.println("PASS: Values are equal");
else
System.out.println("FAIL: Values are not equal");
}
}
Using Java 1.6.0_7:
INFO: intValue2 = 2
INFO: intValue = 2
FAIL: Values are not equal
Using Java 1.6.0_18:
INFO: intValue2 = 2
INFO: intValue = 2
PASS: Values are equal
Whereas, using a non "small" value, such as 123456789, this will fail irrespective of Java version:
Using Java 1.6.0_7:
INFO: intValue2 = 1234567890
INFO: intValue = 1234567890
FAIL: Values are not equal
Using Java 1.6.0_18:
INFO: intValue2 = 1234567890
INFO: intValue = 1234567890
FAIL: Values are not equal