title: Java HashMap with ArrayList wildcards
body: <p>I have a HashMap where the values are ArrayLists, and I'm trying to write a function to accept generic instances of these HashMaps</p>
  
  <pre><code>HashMap&lt;String, ArrayList&lt;Integer&gt;&gt; myMap = new HashMap&lt;String, ArrayList&lt;Integer&gt;&gt;();
  public static void foo(HashMap&lt;?, ArrayList&lt;?&gt;&gt; a) {}
  public static void bar(HashMap&lt;?, ? extends ArrayList&lt;?&gt;&gt; a) {}
  
  // Compilation Failure!
  foo(myMap);
  
  // This works, but why do I need ? extends ArrayList
  bar(myMap)
  </code></pre>
  
  <p>The error message is</p>
  
  <blockquote>
    <p>The method <code>foo(HashMap&lt;?,ArrayList&lt;?&gt;&gt;)</code> in the type <code>Example</code> is not applicable
    for the arguments (<code>HashMap&lt;String,ArrayList&lt;Integer&gt;&gt;</code>).</p>
  </blockquote>
  
  <p>Why do I need to have a wildcard for the extends ArrayList?</p>
  
  <p>I thought that by having <code>ArrayList&lt;?&gt;</code>(without the <code>? extends</code>), I could restrict the function to only HashMaps with ArrayList values.</p>
  
  <p>I also know that the following generic method works:</p>
  
  <pre><code>public static &lt;K,V&gt; void printer(HashMap&lt;K, ArrayList&lt;V&gt;&gt; list) { }
  </code></pre>
  
  <p>Which behaves how I thought <code>ArrayList&lt;?&gt;</code> would work.  Can someone explain the subtleties here?</p>