Java中的装箱和拆箱
来源:华佗健康网
package cn.bdqn.demo01;
public class Demo02 {
public static void main(String[] args) {
/*
* 装箱和拆箱:实现的是基本数据类型和包装类类型之间的自动转换
*/
byte num1 = 10;
// Byte byte1 = new Byte(num1);
// 装箱:基本数据类型直接赋值给包装类类型的对象
Byte byte1 = num1;
// 拆箱:包装类类型数据直接赋值给基本类型的变量
Integer int1 = new Integer("123");
int num2 = int1;
Integer int2 = new Integer("255");
int num3 =300;
int result=int2+num3;
Integer int3 =int2+num3;
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容