Home > Software engineering >  Kotlin : How to remove super when overriding method
Kotlin : How to remove super when overriding method

Time:02-13

I have an abstract base class that has open method for optional implementation.

open fun onBackPressed() = Unit
    
override fun onResume() {
        super.onResume()
        requireView().onBackPress {
            onBackPressed()
        }
    }

When using it in derived class, the method still allows calling of super even though there is nothing to do.

While you can impose a method for calling super using @CallSuper annotation, I need an opposite of it.

CodePudding user response:

EmptySuper is the opposite of CallSuper.

Denotes that any overriding methods should not invoke this method, since it is defined to be empty (or perhaps contain other code not intended to be run when overridden).

  • Related