package chengbaoDemo; public class Test02 { public static void main(String[] args) { Integer i = new Integer(100); //包装类 int i1 = i.intValue(); //手动拆箱 //1.5之后,自动拆箱,装箱 //本质上,是编译器做了代码优化,int i = i.intValue(),自动拆箱 int i2 = i; //本质上, 是编译器做了代码有化, Integer i3 = new Integer(10000); Integer i3 = 1000; /* // 检测是否进行了有化,自动拆箱、自动装箱 Integer i4 = null; //此处出现空指针异常,说明自动拆箱是内部自动调用一方法,出现空指针异常 int i5 = i4 ; //java.lang.NullPointerException */ //缓存问题 Integer i6 = 10000; Integer i7 = 10000; System.out.println(i6 == i7); //false System.out.println(i6.equals(i7)); //true //缓存边界[-128, 127] Integer i8 = -100; Integer i9 = -100; System.out.println(i9 == i8); //true System.out.println(i8.equals(i9)); //true }}
时间: 2024-12-29 12:03:25