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

9.7.1: Clarify that duplicate elements are not permitted in an annotation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 24
    • specification

      javac rejects an annotation that specifies more than one element-value pair for a given element. For example, javac rejects the following annotation because there is more than one element-value pair for the element `forRemoval`:

        @Deprecated(forRemoval = true, forRemoval = false) class Foo {} // rejected by javac

      javac does not care about the value in each element-value pair. For example, if the `forRemoval` element is specified more than once, each time with the _same_ value, then javac still rejects the annotation (as opposed to considering the duplicate element-value pair a "mistake" and ignoring it)

        @Deprecated(forRemoval = true, forRemoval = true) class Bar {} // rejected by javac

      JLS 9.7.1 requires an element-value pair for every non-default element, but does not actually say that specifying more than one element-value pair for a given element is illegal. The JLS should be aligned with javac.

            gbierman Gavin Bierman
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: