mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
!502 在CollectorUtil提交Collectors.toMap的对null友好实现,避免NPE
Merge pull request !502 from 阿超/v5-dev
This commit is contained in:
@@ -150,6 +150,13 @@ public class CollStreamUtilTest {
|
||||
compare.put(2L, map2);
|
||||
Assert.assertEquals(compare, map);
|
||||
|
||||
// 对null友好
|
||||
Map<Long, Map<Long, Student>> termIdClassIdStudentMap = CollStreamUtil.group2Map(Arrays.asList(null, new Student(2, 2, 1, "王五")), Student::getTermId, Student::getClassId);
|
||||
Map<Long, Map<Long, Student>> termIdClassIdStudentCompareMap = new HashMap<Long, Map<Long, Student>>() {{
|
||||
put(null, MapUtil.of(null, null));
|
||||
put(2L, MapUtil.of(2L, new Student(2, 2, 1, "王五")));
|
||||
}};
|
||||
Assert.assertEquals(termIdClassIdStudentCompareMap, termIdClassIdStudentMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user