1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Merge pull request #2673 from Wenweigood/main

优化格式 & 补充集合转Map时的常见异常
This commit is contained in:
Guide 2025-05-13 21:25:30 +08:00 committed by GitHub
commit d3bcbd60b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -134,6 +134,7 @@ public static <T> T requireNonNull(T obj) {
return obj;
}
```
> `Collectors`也提供了无需mergeFunction的`toMap()`方法但此时若出现key冲突则会抛出`duplicateKeyException`异常,因此强烈建议使用`toMap()`方法必填mergeFunction。
## 集合遍历

View File

@ -60,7 +60,7 @@ public class Singleton {
private Singleton() {
}
public static Singleton getUniqueInstance() {
public static Singleton getUniqueInstance() {
//先判断对象是否已经实例过,没有实例化过才进入加锁代码
if (uniqueInstance == null) {
//类对象加锁