This post originated from an RSS feed registered with Java Buzz
by Mike Kaufman.
Original Post: Annotations + Inheritance = Confusion
Feed Title: Closing Braces
Feed URL: https://closingbraces.net/feed/
Feed Description: After-hours notes and opinions on Java and system development.
Whilst Java annotations support an "@Inherit" meta-annotation to specify whether the annotation is inherited or not, some annotations specify far more complex annotation-specific interactions with Java's normal inheritance, hiding and overriding behaviour. This can easily become complex and confusing, especially given the variety of such rules, the use of natural-language descriptions to define them, and the absence of supporting code to implement the rules. Whilst JSR 250 "Common Annotations" includes some general guidelines, even its own annotations remain ambiguous and confusing. This is only likely to get worse as more and more annotations are introduced into Java.
One possible solution might be to provide a more powerful and comprehensive set of meta-annotations for defining annotations. In the meantime I'd urge anybody designing an annotation to try to keep its interaction with inheritance as simple as possible, even if this is less than optimal for that particular annotation, and failing that to provide an implementation for any rules regarding how the annotation should be handled.