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

Type annotation on type arg in method reference crashes javac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 8
    • tools
    • Verified

      While type annotations on most lambda expression are (thus far) ignored, a type annotation on a type argument in a lambda method referece crashses javac.
      Compile TAlamba2.java below:

      import java.lang.annotation.*;
      import static java.lang.annotation.RetentionPolicy.*;
      import static java.lang.annotation.ElementType.*;

      public class TAlambda2 {

          public void test() {
              Integer[] intarray = { new Integer(1), new Integer(2), new Integer(3) };
              printArray(intarray, TPrint::<@A String>print);
          }

          public void printArray(Object[] oa, PrintString ps) {
            for(Object o : oa ) ps.print(o.toString());
          }

          public static void main(String... args) {
              new TAlambda2().test();
          }
      }

      interface PrintString { void print(String s); }

      class TPrint {
          public static <T> void print(T msg) {
              System.out.println("TPrint: " + msg.toString());
          }
      }

      @Retention(RUNTIME)
      @Target({TYPE_USE})
      @interface A {}

            Unassigned Unassigned
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: