对于包装类型Integer的值比较与int的值比较是不同的;
public class Java_Val_Compare { public static void main(String[] args) { Integer a1 = 127; Integer a2 = 127; System.out.println("a1==a2?: "+(a1==a2)); Integer b1 = 128; Integer b2 = 128; System.out.println("b1==b2?: "+(b1==b2)); System.out.println("b1.intValue()==b2.intValue()?: " +(b1.intValue()==b2.intValue())); } }
执行结果: