Final Modifier for Annotations with Subtyping

The JSR 308 proposal mentioned that there might be trust issues for annotations that can be subclassed outside a trusted framework. I contend that this is not a severe problem since it occurs with normal classes already.

To still address this issue, I decided to allow the final modifier for annotations: An annotation that is final cannot be subclassed, just like a final class cannot be extended.

final @interface FinalAnnotation {
String value();

// ERROR: cannot inherit from final FinalAnnotation
@interface SubAnnotation extends FinalAnnotation {
int i();

Again, the change involved only half a dozen lines.


About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in xajavac. Bookmark the permalink.

Leave a Reply