自动装箱与拆箱
自动装箱(Autoboxing)和自动拆箱(Unboxing)是 Java 编译器提供的语法糖,用来在基本类型和包装类型之间自动转换。
- 自动装箱:
int -> Integer - 自动拆箱:
Integer -> int
int a = 10;
Integer b = a; // 自动装箱
Integer c = 20;
int d = c; // 自动拆箱
2026/4/23...大约 4 分钟
自动装箱(Autoboxing)和自动拆箱(Unboxing)是 Java 编译器提供的语法糖,用来在基本类型和包装类型之间自动转换。
int -> IntegerInteger -> intint a = 10;
Integer b = a; // 自动装箱
Integer c = 20;
int d = c; // 自动拆箱