Java中的八种基本数据类型和对应的包装类
| 基本数据类型 | 包装类 |
|---|---|
| byte | Byte |
| short | Short |
| long | Long |
| int | Integer |
| boolen | Boolen |
| char | Charactor |
| float | Float |
| double | Double |
public static void main(String[]args){
Integer integer=1; //装箱
int i=integer; //拆箱
}
装箱、拆箱底层实现
从上面反编译后的代码可以看出,int的自动装箱都是通过Integer.valueOf()方法来实现的,Integer的自动拆箱都是通过integer.intValue来实现的。
本文详细介绍了Java中的八种基本数据类型及其对应的包装类,包括byte、short、long、int、boolean、char、float和double。同时,探讨了装箱和拆箱的底层实现,即自动装箱通过Integer.valueOf()方法,自动拆箱通过integer.intValue方法。
1169

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



