.collect(Collectors.toMap())报错 NullPointerException: null at java.util.HashMap.merge

改进前
Map collect = clientEntities.stream()
        .collect(Collectors
        .toMap(ClientEntity::getClientId,ClientEntity::getUseLocation));

改进后:

Map collect = clientEntities.stream()
        .collect(HashMap::new
                ,(map,client)->map.put(client.getClientId(),client.getUseLocation())
                ,HashMap::putAll);

你可能感兴趣的:(错误,java,java,开发语言,后端)