RFR: 8336754: Remodel TypeAnnotation to "has" instead of "be" an Annotation [v6]

Alex Buckley alex.buckley at oracle.com
Thu Aug 1 20:59:09 UTC 2024


On 8/1/2024 1:02 PM, Chen Liang wrote:
>   * In an annotation in Java source code, elements in the annotation interface
>   * with default values may not be compiled into element-value pairs unless an
>   * explicit value is provided. ({@jls 9.6.2}) The default value is derived from
>   * the {@link AnnotationDefaultAttribute AnnotationDefault} attribute on the
>   * method representing the annotation interface element in the class file
>   * representing the annotation interface.
>   * <p id="repeatable">
>   * Multiple annotations of the same interface <i>A</i> in Java source code
>   * ({@jls 9.7.5}) are represented by the {@linkplain AnnotationValue.OfAnnotation
>   * annotation-valued} array elements of the {@linkplain AnnotationValue.OfArray
>   * array-valued} element named {@code value} of a container annotation of the
>   * containing annotation interface of <i>A</i>. ({@jls 9.6.3})

Very good and precise usage of "annotation" versus "annotation 
interface". The last sentence is rather long; you could break it as "... 
of a container annotation. The interface of the container annotation is 
the containing annotation interface of A."

>       * <p>
>       * A single-element annotation ({@jls 9.7.3}) in Java source code is
>       * compiled to an {@link Annotation} with exactly one {@linkplain
>       * Annotation#elements key-value pair} where the element has the name
>       * {@code value}.

I take issue with "compiled to ...". The annotation is *compiled* to a 
Runtime...Annotations attribute, but it's *represented* by an Annotation 
with exactly one ...  (Just as multiple annotations of the same 
interface are *represented* by the annotation-valued ...)

>       * <p>
>       * Multiple annotations of the same interface <i>A</i> in Java source code
>       * is compiled to an implicitly declared container annotation ({@jls 9.7.5})
>       * with exactly one {@linkplain Annotation#elements key-value pair} where
>       * the element has the name {@code value} and the type of the element is the
>       * {@linkplain AnnotationValue.OfArray array} whose component type is the
>       * {@linkplain AnnotationValue.OfAnnotation annotation interface <i>A</i>}.

Multiple annotations ... *are represented* [not "is compiled"] by a 
container annotation [drop "implicitly declared", that's a compile time 
story but you're discussing run time] with exactly one *element-value* 
pair [never seen "key-value pair" used for annotations]. The name of the 
element is ... and the type of the element is ...

Alex


More information about the compiler-dev mailing list