问题
Did I dream this? I could have swore I read something about java 7 supplying an annotation that you could place on a method to ensure all subclasses call super. Has this been renamed, or dropped, or was it never actually considered?
回答1:
It was part of JSR 305: Annotations for Software Defect Detection and called @OverridingMethodsMustInvokeSuper.
The JSR is inactive, but a reference implementation is available bundled with FindBugs
回答2:
It could have been suggested for project Coin, which accepted many suggested but picked the best/simplest of the list.
You can do this instead.
public final void method() {
// super code
subClassMethod();
}
protected void subClassMethod() {
// can be overridden.
}
来源:https://stackoverflow.com/questions/8448027/what-happened-to-javas-overridingmethodmustcallsuper