title: Enum, interfaces and (Java 8) lambdas: code compiles but fails at runtime; is this expected?
body: <p>JDK is Oracle' JDK 1.8u65 but the problem has been seen with "as low as" 1.8u25 as well.</p>
  
  <p>Here is the full SSCCE:</p>
  
  <pre><code>public final class Foo
  {
      private interface X
      {
          default void x()
          {
          }
      }
  
      private enum E1
          implements X
      {
          INSTANCE,
          ;
      }
  
      private enum E2
          implements X
      {
          INSTANCE,
          ;
      }
  
      public static void main(final String... args)
      {
          Stream.of(E1.INSTANCE, E2.INSTANCE).forEach(X::x);
      }
  }
  </code></pre>
  
  <p>This code compiles; but it fails at runtime:</p>
  
  <pre><code>Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
      at java.lang.invoke.CallSite.makeSite(CallSite.java:341)
      at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
      at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
      at com.github.fge.grappa.debugger.main.Foo.main(Foo.java:38)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type class java.lang.Enum; not a subtype of implementation type interface com.github.fge.grappa.debugger.main.Foo$X
      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:302)
      ... 8 more
  </code></pre>
  
  <p>Fixing it in code is "easy"; in the main method, you just have to:</p>
  
  <pre><code>// Note the &lt;X&gt;
  Stream.&lt;X&gt;of(E1.INSTANCE, E2.INSTANCE).forEach(X::x);
  </code></pre>
  
  <p><strong>EDIT</strong> There is in fact a second way, as mentioned in the accepted answer... Replace the method reference with a lambda:</p>
  
  <pre><code>Stream.of(E1.INSTANCE, E2.INSTANCE).forEach(x -&gt; x.x());
  </code></pre>
  
  <p>So, uh. What happens here? Why does the initial code compile in the first place? I'd have expected the compiler to notice that the method reference was not on anything <code>Enum&lt;?&gt;</code> but on <code>X</code>, but no...</p>
  
  <p>What am I missing? Is this a bug in the compiler? A misunderstanding of mine?</p>