Kotlin: How can I call a super extension function?

How can I call the super extension function?

For example:

open class Parent {
    open fun String.print() = println(this)
}

class Child : Parent() {
    override fun String.print() {
        print("child says ")
        super.print() // syntax error on this
    }
}

      

+3


source to share


1 answer


Even if the function is print()

defined internally Parent

, it belongs to String

, not Parent

. So there is no function print

that you can call Parent

what you are trying to do with super

.



I don't think there is syntactic support for the type of call you are trying to make in Kotlin.

+2


source







All Articles