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