title: Why is this method reference failing at runtime but not the corresponding lambda call?
body: <p>I have these two interfaces. One is public (A), the other one is package private (AA). <code>A</code> extends <code>AA</code>.</p>
  
  <pre><code>package pkg.a;
  
  @FunctionalInterface
  public interface A extends AA {
  
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>package pkg.a;
  
  interface AA {
  
      default void defaultM() {
          System.out.println(m());
      }
  
      String m();
  }
  </code></pre>
  
  <p>I have this code (in a different package):</p>
  
  <pre><code>package pkg;
  
  import java.util.Arrays;
  import java.util.List;
  
  import pkg.a.A;
  
  public class Test {
  
      public static void main(String[] args) {
          List&lt;A&gt; list = Arrays.asList(() -&gt; "imp1", () -&gt; "imp2");
  
          list.stream().forEach(a -&gt; a.defaultM());
          list.stream().forEach(A::defaultM);
      }
  }
  </code></pre>
  
  <p>When running the above code the <code>list.stream().forEach(A::defaultM);</code> throws the below exception. Why? Why can't the method reference access the methods defined in the package-private interface while the lambda expression can? I'm running this in Eclipse (Version: 2018-12 (4.10.0)) with Java version 1.8.0_191.</p>
  
  <pre><code>imp1
  imp2
  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 pkg.Test.main(Test.java:14)
  Caused by: java.lang.IllegalArgumentException: java.lang.IllegalAccessException: class is not public: pkg.a.AA.defaultM()void/invokeInterface, from pkg.Test
      at java.lang.invoke.MethodHandles$Lookup.revealDirect(MethodHandles.java:1360)
      at java.lang.invoke.AbstractValidatingLambdaMetafactory.&lt;init&gt;(AbstractValidatingLambdaMetafactory.java:131)
      at java.lang.invoke.InnerClassLambdaMetafactory.&lt;init&gt;(InnerClassLambdaMetafactory.java:155)
      at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:299)
      at java.lang.invoke.CallSite.makeSite(CallSite.java:302)
      ... 3 more
  Caused by: java.lang.IllegalAccessException: class is not public: pkg.a.AA.defaultM()void/invokeInterface, from pkg.Test
      at java.lang.invoke.MemberName.makeAccessException(MemberName.java:850)
      at java.lang.invoke.MethodHandles$Lookup.checkAccess(MethodHandles.java:1536)
      at java.lang.invoke.MethodHandles$Lookup.revealDirect(MethodHandles.java:1357)
      ... 7 more
  </code></pre>