Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin: How can I call super's extension function?

How can I call a super's 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
    }
}
like image 565
Jire Avatar asked Jun 02 '17 03:06

Jire


1 Answers

Even though the print() function is defined inside of Parent, it belongs to String, not to Parent. So there's no print function that you can call on Parent, which is what you're trying to do with super.

I don't think there's syntax support for the type of call you're trying to do in Kotlin.

like image 199
Varo Avatar answered Nov 08 '22 06:11

Varo