title: java8 Collectors.toMap() limitation?
body: <p>I am trying to use java8's <code>Collectors.toMap</code> on a <code>Stream</code> of <code>ZipEntry</code>. It may not be the best idea because of possible exceptions occuring during the processing, but I guess it ought to be possible.</p>
  
  <p>I am now getting a compile error (type inference engine I guess) which I don't understand.</p>
  
  <p>Here's some extracted demo code:</p>
  
  <pre><code>import java.io.IOException;
  import java.util.Map;
  import java.util.stream.Collectors;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipFile;
  
  public class TestMapCollector {
  
      private static class MyObject {
      }
  
      public static void main(String[] argv) throws IOException {
          try (ZipFile zipFile = new ZipFile("test")) {
              Map&lt;String, MyObject&gt; result = zipFile.stream()
                      .map(ZipEntry::getName)
                      .collect(Collectors.toMap(f -&gt; "test", f -&gt; new MyObject()));
          }
      }
  }
  </code></pre>
  
  <p>This code builds as-is, however it doesn't build if you just comment the <code>.map(ZipEntry::getName)</code> line. As if the <code>toMap</code> collector could work if the input is a stream of <code>String</code> but not if the input is a stream of <code>ZipEntry</code>?</p>
  
  <p>For reference, here is the beginning of the build error, it's quite obscure:</p>
  
  <pre><code>no suitable method found for collect(Collector&lt;Object,CAP#1,Map&lt;String,MyObject&gt;&gt;)
      method Stream.&lt;R#1&gt;collect(Supplier&lt;R#1&gt;,BiConsumer&lt;R#1,? super CAP#2&gt;,BiConsumer&lt;R#1,R#1&gt;) is not applicable
        (cannot infer type-variable(s) R#1
          (actual and formal argument lists differ in length))
      method Stream.&lt;R#2,A&gt;collect(Collector&lt;? super CAP#2,A,R#2&gt;) is not applicable
        (cannot infer type-variable(s) R#2,A,CAP#3,T#2,K,U
          (argument mismatch; Collector&lt;CAP#2,CAP#4,Map&lt;Object,Object&gt;&gt; cannot be converted to Collector&lt;? super CAP#2,CAP#4,Map&lt;Object,Object&gt;&gt;))
    where R#1,T#1,R#2,A,T#2,K,U are type-variables:
      R#1 extends Object declared in method &lt;R#1&gt;collect(Supplier&lt;R#1&gt;,BiConsumer&lt;R#1,? super T#1&gt;,BiConsumer&lt;R#1,R#1&gt;)
      T#1 extends Object declared in interface Stream
      R#2 extends Object declared in method &lt;R#2,A&gt;collect(Collector&lt;? super T#1,A,R#2&gt;)
      A extends Object declared in method &lt;R#2,A&gt;collect(Collector&lt;? super T#1,A,R#2&gt;)
      T#2 extends Object declared in method &lt;T#2,K,U&gt;toMap(Function&lt;? super T#2,? extends K&gt;,Function&lt;? super T#2,? extends U&gt;)
      K extends Object declared in method &lt;T#2,K,U&gt;toMap(Function&lt;? super T#2,? extends K&gt;,Function&lt;? super T#2,? extends U&gt;)
      U extends Object declared in method &lt;T#2,K,U&gt;toMap(Function&lt;? super T#2,? extends K&gt;,Function&lt;? super T#2,? extends U...
  </code></pre>