With Java 9, new factory methods have been introduced for the List
, Set
and Map
interfaces. These methods allow quickly instantiating a Ma
In my opinion non-nullability makes sense for keys, but not for values.
Map
interface becomes a weak contract, you can't trust it's behaviour without looking at the implementation, and that is assuming you have access to see it. Java11's Map.of()
does not allow null values while HashMap
does, but they both implement the same Map
contract - how come?Map.of()
useless as a construct for such structures.