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

[local-methods] Generic local methods are not annotatable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • repo-amber
    • repo-amber
    • tools
    • generic
    • generic

      Compiling the following program:

      public class X {
          @interface A {
          }

          @A
          <T extends X> T id(T t) {
              return null;
          }
      public static void main(String [] args) {
              
              @A
              <T extends X> T id(T t) {
                  return t;
              }

              X x = new X();
              X i = id(x);
              System.out.println("i = " + i + " x = " + x);
      }
      }

      results in:

      X.java:12: error: illegal start of type
              <T extends X> T id(T t) {
              ^
      X.java:12: error: > expected
              <T extends X> T id(T t) {
                 ^
      X.java:12: error: not a statement
              <T extends X> T id(T t) {
                          ^
      X.java:12: error: ';' expected
              <T extends X> T id(T t) {
                             ^
      X.java:12: error: ')' expected
              <T extends X> T id(T t) {
                                  ^
      X.java:12: error: not a statement
              <T extends X> T id(T t) {
                                   ^
      X.java:12: error: ';' expected
              <T extends X> T id(T t) {
                                    ^
      7 errors

      See that the instance method is annotatable while the local method is not.

            vromero Vicente Arturo Romero Zaldivar
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: