What happened to Java's @OverridingMethodMustCallSuper?

时间秒杀一切 提交于 2019-12-10 16:53:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!