java 类型 装箱和拆箱

装箱

Integer i =1 //自动装箱,基本类型转换为对象
Integer j = Integer.valueOf(1) //一般不适用new Integer(),因为valueOf还利用了缓存,效率高一些

拆箱

int x = i;//自动拆箱
int y = i.toInt(//)

参考:
https://www.cnblogs.com/linjiaxin/p/6393380.html

猜你喜欢

转载自blog.csdn.net/claroja/article/details/114199031
今日推荐