例子:
1 public class Test { 2 3 public static void main(String[] args) { 4 5 Integer i = new Integer(128); 6 Integer i2 = 128; 7 8 System.out.println(i == i2); 9 10 Integer i3 = new Integer(127); 11 Integer i4 = 127; 12 System.out.println(i3 == i4); 13 14 Integer i5 = 128; 15 Integer i6 = 128; 16 System.out.println(i5 == i6); 17 18 Integer i7 = 127; 19 Integer i8 = 127; 20 System.out.println(i7 == i8); 21 } 22 }
输出的结果为:
false false false true