自动装箱与拆箱
自动装箱(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; // 自动拆箱
Java 集合,HashMap、Hashtable、ConcurrentHashMap 这几个类很容易被混在一起。
表面上看,它们都像是“键值对容器”,但如果往并发场景里一放,差别就会立刻出来:
HashMap 线程不安全Hashtable 是线程安全的,但锁太粗ConcurrentHashMap 既要保证线程安全,又希望尽量把并发性能保住