Annotation Type OverridingMethodsMustInvokeSuper


  • @Documented
    @Target(METHOD)
    @Retention(CLASS)
    public @interface OverridingMethodsMustInvokeSuper
    Indicates that any concrete method that overrides the annotated method, directly or indirectly, must invoke super.theAnnotatedMethod(...) at some point. This does not necessarily require an unconditional call; any matching call appearing directly within the method body (not inside an intervening class or lambda expression) is acceptable.

    If the overriding method is itself overridable, applying this annotation to that method is technically redundant, but may be helpful to readers.

    Preferred: usually, a better solution is to make the method final, and have its implementation delegate to a second concrete method which is overridable (or to a function object which subclasses can specify). "Mandatory" statements remain in the final method while "optional" code moves out. This is the only way to make sure the statements will be executed unconditionally.