Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7065524

Compiler error - java.lang.IllegalArgumentException when compiling some method references code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • 8
    • 8
    • tools
    • None
    • generic
    • generic

    Description

      When compiling the following code:

      ----------------------------------------
      import java.lang.reflect.Method;

      public class BridgeMethod {
          interface K<T> {void m(T t);}
          interface M {void m(String s);}
          interface KM extends K<String>, M{} //generic substitution
          
          private static void assertTrue(boolean cond) {
              if (!cond)
                  throw new AssertionError();
          }

          static void bar(String s) {
              System.out.println("BridgeMethod.bar(String) " + s);
          }

          public static void main(String[] args) {
              KM km = BridgeMethod#bar(String); //<<<<<<<<<<<<<<<<<error occurs here
              ...
      ----------------------------------------

      The following compiler error was encountered:
      ----------System.err:(13/756)----------
      java.lang.IllegalArgumentException: not a single-method interface: BridgeMethod$KM
      at java.lang.invoke.MethodHandleProxies.asInterfaceInstance(MethodHandleProxies.java:140)
      at BridgeMethod.main(BridgeMethod.java:70)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
      at java.lang.Thread.run(Thread.java:722)

      Where KM IS a SAM interface.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              suwei Sue Wei
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: