TYPE_USE target and repeatable annotations.

Srikanth S Adayapalam srikanth_sankaran at in.ibm.com
Sun Nov 10 22:51:57 PST 2013

Hello !

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;

@interface Foo {}
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface FooContainer {
        Foo[] value();

// --

ECJ error message: The container annotation type @FooContainer is allowed 
at targets where the repeatable annotation type @Foo is not: TYPE
javac error message: X.java:6: error: target of container annotation 
FooContainer is not a subset of
target of repeated annotation Foo.

>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 
Foo's applicability. Specifically, the kind of program element where 
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.

What do we want to say about this case ? 


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