装箱与拆箱

装箱:将基本数据类型的值给类类型

拆箱:将类类型的值给基本数据类型

自动装箱:装箱的缩写

自动拆箱:拆箱的缩写



public class Wrapper {



public static void main(String[] args) {

Integer i=new Integer(30);//手动装箱,将一个int型的值给Integer类类型

int num=i.intValue();//手动拆箱,将一个Integer类类型的值给int型

Integer m=30;//自动装箱Integer m=new Integer(30);

int x=m;//自动拆箱int x=m.intValue();

}


}

你可能感兴趣的:(装箱与拆箱)