package com.test;
/**
* J2SE 新特性, 自动拆箱和装箱。
*
*/
public class AutoBox {
/**
* 基本数据
*/
public static void intAutoBox(){
int i = 1000;
//可以把基本数据类形直接赋给对象
Integer iObj = 200; //直接装箱
Integer tempObj = iObj;
iObj = 444;
System.out.println(tempObj);
System.out.println(iObj);
// iObj = i;
// i = tempObj; //将对象拆箱
//
//
// iObj += i + tempObj;
// i *= iObj + tempObj;
}
public static void main(String[] args) throws Exception{
intAutoBox();
}
}
本文通过一个简单的Java示例介绍了J2SE中的自动装箱和拆箱特性。示例展示了如何将基本数据类型自动转换为对应的包装类对象,以及如何从包装类对象中获取基本数据类型的值。
1020

被折叠的 条评论
为什么被折叠?



