Java的包装类介绍(五)自动拆装箱

版权声明:转载注明来源。Keep Learning and Coding. https://blog.csdn.net/a771581211/article/details/88287544
package day02;
/**
 * JDK1.5之后推出了一个新特性
 * 自动拆装箱
 * @author kaixu
 *
 */
public class IntegerDemo5 {

	public static void main(String[] args) {
		/*
		 * 自动拆装是编译器认可,而不是虚拟机认可。
		 * 编译器在将源程序编译时自动补充代码来完成基本类型与包装类型之间的转换。
		 * 
		 * 下面的代码触发了自动拆箱:
		 * 在class文件中,下面的代码被编译器改为注释部分。
		 */
		int i = new Integer(1);  //相当于int i = new Integer(1).intValue();
		
		/*
		 * 下面的代码触发了自动装箱:
		 * 在class文件中,下面的代码被编译器改为注释部分。
		 */
		
		Integer ii = 123;  //相当于Integer ii = Integer.valueOf(123);
	}

}

猜你喜欢

转载自blog.csdn.net/a771581211/article/details/88287544