class Foo { public void foo() { Integer a = 128; Integer b = (int) a;// cast is necessary because new object is created Integer c = 128; System.out.println(a == b); System.out.println(a == c); System.out.println((Long)128L == (Long)128L); System.out.println(128 == 128); System.out.println((Long)128L != (Long)128L); System.out.println(128 != 128); } }