加载中...

自动装箱、自动拆箱

/**
测试自动装箱、自动拆箱
*/
public class TestAutoBox {
public static void main(String[] args) {
Integer a = 234; //自动装箱。Integer a = Integer.valueOf(234);
int b = a; //自动拆箱。编译器会修改成:int b = a.intValue();

System.out.println("a = "+a);
System.out.println("b = "+b);

Integer c = null;
if(c!=null) {
int d = c; //自动拆箱:调用:c.intValue();
}
}
}

posted @ 2021-08-14 10:54  nongeason  阅读(54)  评论(0)    收藏  举报