TYPE_USE target and repeatable annotations.

Srikanth S Adayapalam srikanth_sankaran at in.ibm.com
Mon Nov 11 01:02:03 PST 2013

> From: Srikanth S Adayapalam/India/IBM
> Subject: TYPE_USE target and repeatable annotations.

> The following program fails to compile with both javac and ECJ:
> // --
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Repeatable;
> import java.lang.annotation.Target;
> @Target({ElementType.TYPE_USE})
> @Repeatable(FooContainer.class)
> @interface Foo {}
> @Target({ElementType.TYPE, ElementType.TYPE_USE})
> @interface FooContainer {
>  Foo[] value();
> }


> From the spec:
> If Foo has an @Target meta-annotation, then in the judgment of the 
> designers of the
> Java programming language, FooContainer must be declared with knowledge 
of the
> Foo's applicability. Specifically, the kind of program element where 
> FooContainer
> may appear must be the same as, or a subset of, Foo's kinds.
> Given TYPE_USE annotations can appear on type declarations, the
> last sentence is certainly valid for the program above.

Not quite, just after pushing the send button, I realized that 
by virtue of its TYPE target, can appear on annotation types, while @Foo
cannot. So there is no contradiction here. 

I'll withdraw this issue as requiring no follow up on the spec side.

Note however that 8b112 does not complain on this program, I believe 
it should, given that annotation type uses cannot be type annotated,
the short hand of annotating the declaration should also be invalid.

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@interface Foo {}

@interface Marker {


More information about the type-annotations-spec-experts mailing list