How to stop Kotlin from override onDestroyView() in Fragment?


#1

How to stop Kotlin from override onDestroyView() in Fragment?

In our Base Fragment, we define the method onDestroyView() as final so the child won’t override it.

But Kotlin will override the method to call clearFindViewByIdCache().

Is there a solution?


#2

You have three options:

  • Don’t use the Kotlin Android extensions
  • Don’t make the function final. You can still use a static analyser to check for manual overrides.
  • For the android extensions to have a different way to clear the cache.