Integer的自动装箱与拆箱
//Integer的自动装箱与拆箱
//JVM会自动缓存-128~127范围内的值
public class IntegerDemo {
public static void main(String[] args) {
int a1=10;
Integer a2=10;
Integer a3=10;
Integer a4=new Integer(10);
int b1=1000;
Integer b2=1000;
Integer b3=1000;
Integer b4=new Integer(1000);
System.out.println(a1==a2);//true
System.out.println(a1==a4);//true
System.out.println(a2==a3);//true
System.out.println(a2==a4);//false
System.out.println("1--------");
System.out.println(b1==b2);//true
System.out.println(b1==b4);//true
System.out.println(b2==b3); //false
System.out.println(b2==b4);//false
System.out.println("2--------");
Integer c1=127,c2=128;
int c3=128;
c1=c3;//装箱
System.out.println(c1==c2);//false
System.out.println(c1==c3);//true
System.out.println(c2==c3);//true
System.out.println("3-----------");
Integer d1=127;
Integer d2=127;
System.out.println(d1==d2);//true
d1=128;
d2=128;
System.out.println(d1==d2);//false
}
}