<p>How to do this in Java - passing a collection of subtype to a method requiring a collection of base type?</p>

<p>The example below gives:</p>

<pre><code>The method foo(Map&lt;String,List&gt;) is not applicable for the arguments (Map&lt;String,MyList&gt;)
</code></pre>

<p>I can implement by creating a class hierarchy for the typed collections - but is it possible otherwise?</p>

<pre><code>public void testStackOverflow() {

    class MyList extends AbstractList {
        public Object get(int index) {
            return null;
        }
        public int size() {
            return 0;
        }           
    };

    Map &lt;String, List&gt;   baseColl = null;
    Map &lt;String, MyList&gt; subColl  = null;

    foo (subColl);              
}

private void foo (Map &lt;String, List&gt; in) {      
}
</code></pre>

<p>EDIT: Turns out from the answers that this requires "bounded wildcard" so adding this text for searchability</p>

Change
```
foo
```
to:
```
```
private void foo(Map <String, ? extends List> in) {
}
```
```
That will restrict what you can do within
```
foo
```
, but that's reasonable. You know that any value you fetch from the map will be a list, but you don't know what kind of value is valid to put into the map.