title: Why does Map.of not allow null keys and values?
body: <p>With Java 9, new factory methods have been introduced for the <code>List</code>, <code>Set</code> and <code>Map</code> interfaces. These methods allow quickly instantiating a Map object with values in one line. Now, if we consider: </p>
  
  <pre><code>Map&lt;Integer, String&gt; map1 = new HashMap&lt;Integer, String&gt;(Map.of(1, "value1", 2, "value2", 3, "value3"));
  map1.put(4, null);
  </code></pre>
  
  <p>The above is allowed without any exception while if we do:</p>
  
  <pre><code>Map&lt;Integer, String&gt; map2 = Map.of(1, "value1", 2, "value2", 3, "value3", 4, null );
  </code></pre>
  
  <p>It throws:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at java.base/java.util.Objects.requireNonNull(Objects.java:221)
  ..
  </code></pre>
  
  <p>I am not able to get, <strong>why null is not allowed</strong> in second case. </p>
  
  <p>I know HashMap can take null as a key as well as a value but why was that restricted in the case of Map.of? </p>
  
  <p>The same thing happens in the case of <code>java.util.Set.of("v1", "v2", null)</code> and <code>java.util.List.of("v1", "v2", null)</code>.</p>