title: Java generics collection wildcard capture
body: <p>I understand that the intricacies of Java generics can get... intricate. I figure that if I have a Google Guava multimap with a <code>Collection&lt;? extends FooBar&gt;</code>, I should be able to use <code>getMap()</code> to assign that to a <code>Map&lt;String, ? extends FooBar&gt;</code>. But I can't do that in Eclipse 4.4RC2; it tells me, "Type mismatch: cannot convert from <code>Map&lt;String,Collection&lt;capture#1-of ? extends EclipseGenerics.FooBar&gt;&gt;</code> to <code>Map&lt;String,Collection&lt;? extends EclipseGenerics.FooBar&gt;&gt;</code>".</p>
  
  <pre><code>import java.util.*;
  
  import com.google.common.collect.*;
  
  public class EclipseGenerics {
  
    public static interface FooBar {
      public String getFoo();
    }
  
    public static &lt;FB extends FooBar&gt; SetMultimap&lt;String, FB&gt; groupFooBarByBar(final Iterable&lt;FB&gt; foobars) {
      final SetMultimap&lt;String, FB&gt; groupedFoobars = HashMultimap.create();
      for (final FB foobar : foobars) {
        groupedFoobars.put(foobar.getFoo(), foobar);
      }
      return groupedFoobars;
    }
  
    public static void test() {
      Collection&lt;FooBar&gt; foobars = new ArrayList&lt;&gt;();
      final SetMultimap&lt;String, ? extends FooBar&gt; groupedFooBars = groupFooBarByBar(foobars);
      //why can't I do this?
      final Map&lt;String, Collection&lt;? extends FooBar&gt;&gt; map = groupedFooBars.asMap();
    }
  
  }
  </code></pre>
  
  <p>I cannot do this:</p>
  
  <pre><code>final Map&lt;String, Collection&lt;? extends FooBar&gt;&gt; map = groupedFooBars.asMap();
  </code></pre>
  
  <p>Why not? <code>asMap()</code> should return <code>Map&lt;K,Collection&lt;V&gt;&gt;</code>.</p>
  
  <p>But I can do this!</p>
  
  <pre><code>final Map&lt;String, ? extends Collection&lt;? extends FooBar&gt;&gt; map = groupedFooBars.asMap();
  </code></pre>
  
  <p>I get a similar error with Oracle's Java 1.8 javac compiler, so either Eclipse 4.4RC2 and Oracle are both wrong, or (more likely) I'm still not a complete expert on Java generics.</p>
  
  <p>Anyone care to explain why <code>Map&lt;String, Collection&lt;? extends FooBar&gt;&gt;</code> doesn't work, but <code>Map&lt;String, ? extends Collection&lt;? extends FooBar&gt;&gt;</code> does work?</p>