With Java 9, new factory methods have been introduced for the List
, Set
and Map
interfaces. These methods allow quickly instantiating a Ma
Exactly - a HashMap
is allowed to store null, not the Map
returned by the static factory methods. Not all maps are the same.
Generally as far as I know it has a mistake in the first place to allow nulls in the HashMap
as keys, newer collections ban that possibility to start with.
Think of the case when you have an Entry in your HashMap
that has a certain key and value == null. You do get, it returns null
. What does the mean? It has a mapping of null
or it is not present?
Same goes for a Key
- hashcode from such a null key has to treated specially all the time. Banning nulls to start with - make this easier.