- 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.

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.

[2] [3]Share [4]