1 class TestAuto{ 2 public static void main(String[] args){ 3 int i = 1; 4 Integer a = 1; 5 Integer b = 2; 6 Integer c = 3; 7 Integer d = 3; 8 Integer e = 321; 9 Integer f = 321; 10 Long g = 3L; 11 System.out.println(i == a);//true 12 System.out.println(c == d);//true 13 System.out.println(e == f);//false 14 System.out.println(c == (a + b));//true 15 System.out.println(c.equals(a + b));//true 16 System.out.println(g == (a + b));//true 17 System.out.println(g.equals(a + b));//false 18 } 19 }
鉴于包装类的“==”在不遇到算数运算的情况下不会自动拆箱(但是看上面的输出好像可以自动拆箱)
以及它们的equals()方法不处理数据转型的关系
时间: 2024-10-15 09:22:52