background
Because the basic data types do not have object-oriented characteristics. So each basic data type corresponds to a packaging class.
Basic data type | Corresponding packaging |
---|---|
byte | Byte |
short | Short |
int | Interger |
long | Long |
float | Float |
double | Double |
char | Character |
boolean | Boolean |
Conversion of basic data types and packaging classes
Packing (basic -> packing) and
unpacking (packing -> basic)
after jdk1.5 supports automatic packing and unpacking
int a = 10;
// 手动装箱
Interger interger = new Interger(a);
// 自动装箱
Interger interger = a;
// 手动拆箱
int b = interger.intValue();
// 自动拆箱
int b = interger;