Is a TYPE_USE annotation stored as such in a class file?
Alex Buckley
alex.buckley at oracle.com
Thu Feb 16 23:36:29 UTC 2023
On 2/16/2023 3:18 PM, Laird Nelson wrote:
> On Thu, Feb 16, 2023 at 3:10 PM Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>
> Looking at an annotation interface `A`'s @Target meta-annotation
> absolutely does tell you all the places that the annotation `@A` may
> appear. Everything about this is checked at compile time -- it has
> to be deterministic.
>
> For example, from `@Target(TYPE_USE)`, you can deduce that `@A` may
> appear on type uses, on class declarations, on interface declarations,
> and on type parameter declarations.
>
>
> Let me put it a different way: what does annotating my annotation
> with @Target({ ElementType.TYPE, ElementType.TYPE_PARAMETER,
> ElementType.TYPE_USE }) accomplish that simply annotating it
> with @Target({ ElementType.TYPE_USE }) does not?
It communicates intent more fully to a third-party checker system that
inspects annotations throughout a program and may apply custom rules
depending on the specified @Target. For example, a TYPE_USE-only
annotation that appears on a class declaration is legal in the Java
language, but may raise semantic issues for a checker, which can be
addressed by adding TYPE to TYPE_USE in the @Target.
Alex
More information about the compiler-dev
mailing list