While you cannot force the code to call your superclass at compile time, it is not so difficult to detect at runtime when the code does not call the superclass.
class Foo { private boolean baseCalled; public final void bar(Thing thing) { baseCalled = false; barImp(thing); if (!baseCalled) { throw new RuntimeException("super.barImp() not called"); } } protected void barImp(Thing thing) { baseCalled = true; . . .
Note that this continues to several levels of inheritance without further elaboration. This method works especially well for methods called from Foo ; in these cases, you can often refuse the qualifier and redirect final to the implementation method and simply define the base class method for setting the flag. Flag clearing will be performed at each call point.
The above template is widely used in the Android platform. This does not guarantee that super.barImp was named first in the override of the subclass; he has just been called.
source share