[JSR308] Annotation Inheritance & annotation's composition

Maxim Kizub mkizub at gmail.com
Mon Oct 6 03:22:48 EDT 2008


Hello.

Annotation inheritance (with multiple super-annotations) may also be
used as a composition for annotations.
For example, if we have @Public, @Static, @Final annotations, one may
add an annotation
@Singleton extends @Public, @Static, @Final
and use it instead of specifying all these three annotations.

The annotation inheritance may also be used for specifying default
final (sealed) values of super-annotations. Like
@Access { int value(); }
final @Public extends @Access { final int value() default 1; }
final @Private extends @Access { final int value() default 0; }

Thus, the inheritance of annotations rises a question, if we have
@Public class Foo {}
and take
Foo.class.getAnnotation(Access.class)
shell it return the instance of @Public annotation, or null?
And if we have
@Public @Access(0) class Foo {}
shell it yield a compilation-time error (since @Access is not allowed
to have multiple annotations
attached to one item)? Shell the

@Singleton extends @Public, @Static, @Final
@MyAPI extends @Public, @Serializable
@Singleton @MyAPI class Foo {}
cause the compile-time error (since both provide a value for @Public)
? Or it shell be treated by compiler as
@Public @Static @Final @Serializable class Foo {}
?

Regards
  Maxim Kizub



More information about the JSR308 mailing list