小编use*_*501的帖子

Kotlin:如何调用扩展方法的超级实现

在 Kotlin 中我有如下代码:

open class A {
    protected open fun B.doSomething() {}
}

class B {}

class C : A() {

    override fun B.doSomething() {
        print("first, do some C-specific logic")
        print("now try to call super implementation. How?")
        super.doSomething() // does not compile
        super<A>.doSomething() // does not compile
        super<B>.doSomething() // does not compile
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道,在这种情况下如何调用 doSomething() 的超类实现?或者根本不可能在 kotlin 中调用扩展函数的超级实现?

extension-methods overriding kotlin

4
推荐指数
1
解决办法
1547
查看次数

标签 统计

extension-methods ×1

kotlin ×1

overriding ×1