- A Concurrent Affair - https://www.concurrentaffair.org -

Final Modifier for Annotations with Subtyping

The JSR 308 proposal mentioned that there might be trust issues [1] 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 [2] value();
}

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

Again, the change involved only half a dozen lines.

[3] [4]Share [5]