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

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 24
    • Component/s: 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.

            Assignee:
            Gavin Bierman
            Reporter:
            Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: