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

9.6.4.1: Expand no-@Target to mean "applicable in all contexts"

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 14
    • 13
    • specification

      Per https://mail.openjdk.java.net/pipermail/compiler-dev/2019-September/013705.html the applicability of an annotation type is at best questionable and at worst unclear in the scenario where no @Target meta-annotation is present on the annotation type's declaration. Expanding the applicability of such an annotation type to ALL contexts is easy to understand, helpful for the vast majority of programs, and future-proof against a growing Java language. Proposal:

      -----
      If an annotation of type java.lang.annotation.Target is not present on the declaration of an annotation type T, then T is applicable in all nine declaration contexts and all 16 type contexts.

      [Delete this informative paragraph] ~~These contexts are the syntactic locations where annotations were allowed in Java SE 7.~~
      -----

      This expansion is source, binary, and behaviorally compatible because it has always been legal to specify all contexts by spelling out every enum constant of j.l.a.ElementType in an @Target meta-annotation. (2021 update: It would be more accurate to say "_largely_ behaviorally compatible", because annotation processors could in theory be confused by type annotations suddenly appearing due to no-@Target annotations applied in various ambiguous locations.)

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: