Kotlin Activity cannot be extended. This type is final, so it cannot be inherited

Logo picture Logo · Jul 18, 2017 · Viewed 19.8k times · Source

I have created a Kotlin Activity, but I am not able to extend the activity. I am getting this message: This type is final, so it cannot be inherited from. How to remove final from Kotlin's activity, so it can be extended?

Answer

Girish Arora picture Girish Arora · Aug 16, 2017

As per Kotlin documentation, open annotation on a class is the opposite of Java's final. It allows others to inherit from this class. By default, all classes in Kotlin are final.

open class Base {
    open fun v() {}
    fun nv() {}
}

class Derived() : Base() {
    override fun v() {}
}

Refer :https://kotlinlang.org/docs/reference/classes.html