扩展方法是否遵循C#中面向对象的范例?
使用扩展方法是一个好习惯吗?
在软件开发生命周期中,我们应该如何在设计阶段考虑这个问题?
在 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 中调用扩展函数的超级实现?