martmists
12/21/2022, 2:21 AMopen class A {
open fun C.extMethod() { ... }
}
class B : A() {
override fun C.extMethod() {
// Somehow call A's implementation
// Then do extra behavior
}
}
super.extMethod(this)
doesn't seem to resolve unfortunatelyJosh Eldridge
12/21/2022, 3:08 AMinterface Foo {
fun Bar.bar()
}
open class BaseClass : Foo {
open fun doSomethingWithBar(bar: Bar) {
println("parent impl")
}
override fun Bar.bar() = doSomethingWithBar(this)
}
class SubClass : BaseClass() {
override fun Bar.bar() {
super.doSomethingWithBar(this) // now works
println("subclass")
}
override fun doSomethingWithBar(bar: Bar) {
bar.bar()
}
}
fun main(args: Array<String>) {
val theClass = SubClass()
theClass.doSomethingWithBar(Bar())
// parent impl
// subclass
}
Stephan Schröder
12/21/2022, 8:26 AMextMethod
an extension method, by moving the context C to the first parameter of the method.
open class A {
open fun method(c: C) { ... }
}
class B : A() {
override fun method(c: C) {
// call A's implementation
super.method(c)
// Then do extra behavior
}
}
You probably knew that, so i mention this just for the sake of completeness.