【发布时间】:2018-02-27 06:44:12
【问题描述】:
为什么 HashMap 合并对值进行空值检查。 HashMap 支持空键和空值。那么有人可以告诉为什么需要对合并进行空检查吗?
@Override
public V merge(K key, V value,
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
if (value == null)
throw new NullPointerException();
if (remappingFunction == null)
throw new NullPointerException();
因此,我无法使用Collectors.toMap(Function.identity(), this::get) 在地图中收集值
【问题讨论】:
-
您咨询documentation了吗?
标签: java-8 collectors