自动装箱:就是自动将基本数据类型转换为包装器类型
public static void main(String[] args){
int a=3;
Integer b=a;//这里就是自动装箱的过程
System.out.println(b);
}
程序在执行Integer b=a;
的时候调用了Integer.valueOf ( int i ) 方法,`Integer b=a; 这段代码等同于:Integer b=Integer.valueOf ( a ) 。
自动拆箱:就是自动将包装器类型转换为基本数据类型
public static void main(String[] args){
Integer b=new Integer(3);
int a=b;//这里就是自动拆箱的过程
System.out.println(a);
}
int a=b,这段代码等价于:int a=b.intValue()。