- 自动装箱,自动拆箱
-
- 缓存问题
-
public class TestIntegerCache {
public static void main(String[] args) {
Integer i1 = 1234;//自动装箱,编译器时 Integer i1 = new Integer(1234);
Integer i2 = 1234;
System.out.println(i1==i2);//false
System.out.println(i1.equals(i2));//true
System.out.println("###################");
Integer i3 = 123;
Integer i4 = 123;
System.out.println(i3==i4);//true,注意,在[-128,127]之间存在缓存问题
System.out.println(i3.equals(i4));//true
}
}
-
public class TestIntegerCache {
public static void main(String[] args) {
Integer i1 = 1234;//自动装箱,编译器时 Integer i1 = new Integer(1234);
Integer i2 = 1234;
System.out.println(i1==i2);//false
System.out.println(i1.equals(i2));//true
System.out.println("###################");
Integer i3 = 123;
Integer i4 = 123;
System.out.println(i3==i4);//true,注意,在[-128,127]之间存在缓存问题
System.out.println(i3.equals(i4));//true
}
}