To play with autoboxing and understand it better, I developed this piece of code in JAVA:
public class Autoboxing {
public static void cmp(Integer a, Integer b) {
if (a < b) System.out.printf("%d < %d\n", a, b);
else if (a == b) System.out.printf("%d == %d\n", a, b);
else System.out.printf("%d > %d\n", a, b);
}
public static void main (String[] args) {
cmp(new Integer(42), new Integer(42));
cmp(42, 42);
cmp(128, 128);
}
}
I would expect the result to be:
42 > 42
42 == 42
128 == 128
But the actual result differs for the last line. It gives me:
128 > 128
What exactly is going on here, so that the primitive 42 is behaving like I would expect (giving me the equals result), but the primitive 128 is not?