我有一个Map (多个地图,有几种),签名如下:
代码语言:javascript运行复制Map
这是我的相关代码:
代码语言:javascript运行复制motherChildIndex
.getOrDefault(personId, Collections.emptySet()) //personId is just a string that may or may not be in the map, hence getOrDefault
.stream() //I get the warning here
.map(personsIndex::get) //Not important to reproduce
.forEach(children::add); //Not important to reproduce在.stream()线路上,我收到一个警告:
方法调用“流”可以生成“java.lang.NullPointerException”
为什么?我以为getOrDefault()不应该返回空的。
我正在使用Android作为我的IDE,如果这有什么区别的话。