Annotate interface function that must call super

android, annotations, kotlin

Solution

I've accidentally found, what I was looking for. It's a `@CallSuper` annotation available in `androidx.annotation` package. Docs

Use the @CallSuper annotation to validate that an overriding method calls the super implementation of the method. The following example annotates the onCreate() method to ensure that any overriding method implementations call super.onCreate():

@CallSuper
protected fun onCreate(savedInstanceState: Bundle?) {
}

Problem

I'm creating interface and some function in it has a body. It's required, that class that implements this interface must call super in overriding function before executing other code. How can I do this? ``` interface Watcher { fun funWithoutBody() fun startWatching() { //do some important stuff which must be called } } ```

Original source