@Target on Repeatable annotation but no @Target on the containing annotation

Alex Buckley alex.buckley at oracle.com
Tue Oct 1 16:02:08 PDT 2013


You are correct. FooContainer is applicable in all the locations where 
it was applicable in SE 7 (JSR 308 has a fuller explanation of this), 
which is to say, type declarations and method declarations and field 
declarations and so on. Foo must be applicable to at least those same 
locations, but it isn't. Technically, in the code below, FooContainer is 
not a containing annotation type of Foo, and javac correctly gives an 
error for @Repeatable(FooContainer.class).

Alex

On 10/1/2013 1:20 PM, Jesper Steen Møller wrote:
> Hi List
>
> Consider the following example:
>
> import java.lang.annotation.Target;
> import java.lang.annotation.ElementType;
>
> @interface FooContainer {
>    Foo[] value();
> }
>
> @java.lang.annotation.Repeatable(FooContainer.class)
> @java.lang.annotation.Target({ElementType.FIELD})
> @interface Foo {
> }
>
> The spec doesn't address this case as directly as it handles the others - but as I read it, then since @Foo is constrained to specific targets, and @FooContainer is not, this should be flagged as an error, right?
>
> -Jesper
>


More information about the enhanced-metadata-spec-discuss mailing list