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

annotations in the super class constructor are not propagated to the anonymous class constructor

XMLWordPrintable

      Parameter annotations being copied to inner classes was introduced in JDK-8010737

      The behaviour of this cannot be verified using the javap tool.

      When running javap on the following example:

      @Target(value = {ElementType.PARAMETER})
      @interface ParamAnnotation {}

      public class initParams {
         public initParams(@ParamAnnotation int i) {}

         public void m() {
             new initParams(2) {};
         }
      }

      Parameter annotations are only visible in the output when using the tool against the parent constructor

      Output snippet:
         RuntimeInvisibleParameterAnnotations:
            0:
              0: #12()

      When using the tool against the class file generated for the anonymous class, no such Parameter Annotations can be seen in the output

      Note: other annotations are not copied either like `constructor` and type annotations

            vromero Vicente Arturo Romero Zaldivar
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: