[JSR308] Annotation Inheritance & annotation's composition

Niko Matsakis niko at alum.mit.edu
Mon Oct 6 04:08:33 EDT 2008


On Oct 6, 2008, at 9:22 AM, Maxim Kizub wrote:
> 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)?

This is one reason why I included both multiple annotations AND  
inheritance together in my proposal, though personally for what I am  
doing multiple annotations would be the more useful of the two.

However, for those cases where multiple annotations are prohibited,  
then I think these examples would simply result in static errors.

Also, if @Foo extends @Bar, and the user asks for any instances of  
Bar.class, then I think the @Foo annotation should be returned.


Niko



More information about the JSR308 mailing list