Thursday, December 27, 2018

Java 8 : Collectors.toMap | Do you know that Values cannot be null?

In Java Map, you can have null key and null values as well.

But when you are using Collectors.toMap() be wary not to have a KeyMapper and ValueMapper that will give null keys or null values.

Internally it uses Map.merge which will throw NPE if key or value is null. This is an open bug at JDK


Reference :
https://stackoverflow.com/questions/24630963/java-8-nullpointerexception-in-collectors-tomap 

No comments:

Post a Comment