java的8种基本类型都有其对应的装箱类型:
基本类型 | 比特位 | 装箱类型 | |
---|---|---|---|
整型 | byte | 8 | Byte |
short | 16 | Short | |
int | 32 | Integer | |
long | 64 | Long | |
浮点型 | float | 32 | Float |
double | 64 | Double | |
文本型 | char | 16 | Character |
逻辑型 | boolean | 8 | Boolean |
注:装箱类型比基本类型多一个非功能值null。
自动装箱:valueOf(int i)
自动拆箱:intValue()
基本类型优于装箱类型:
什么时候使用装箱类型:
常见问题: