title: LambdaConversionException with generics: JVM bug?
body: <p>I have some code with a method reference that compiles fine and fails at runtime.</p>
  
  <p>The exception is this:</p>
  
  <pre><code>Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type class redacted.BasicEntity; not a subtype of implementation type interface redacted.HasImagesEntity
      at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:233)
      at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
      at java.lang.invoke.CallSite.makeSite(CallSite.java:289)
  </code></pre>
  
  <p>The class triggering the exception:</p>
  
  <pre><code>class ImageController&lt;E extends BasicEntity &amp; HasImagesEntity&gt; {
      void doTheThing(E entity) {
          Set&lt;String&gt; filenames = entity.getImages().keySet().stream()
              .map(entity::filename)
              .collect(Collectors.toSet());
      }
  }
  </code></pre>
  
  <p>The exception is thrown trying to resolve <code>entity::filename</code>. <code>filename()</code> is declared in <code>HasImagesEntity</code>. As far as I can tell, I get the exception because the erasure of E is <code>BasicEntity</code> and the JVM doesn't (can't?) consider other bounds on E.</p>
  
  <p>When I rewrite the method reference as a trivial lambda, everything is fine. It seems really fishy to me that one construct works as expected and its semantic equivalent blows up.</p>
  
  <p>Could this possibly be in the spec? I'm trying very hard to find a way for this not to be a problem in the compiler or runtime, and haven't come up with anything.</p>