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.

1
2
3
4
5
6
7
8
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

Ph.D. Candidate in the Department of Computer Science at Rice University.
This entry was posted in xajavac. Bookmark the permalink.

Leave a Reply