When using Class Delegation, is there a way to access the internally stored object without providing it in the primary constructor and storing it in a property?
interface Base {
fun a()
}
class BaseImpl : Base {
override fun a() {}
fun b() {}
}
class Derived : Base by BaseImpl() {
fun c() {
// Is there a way to call b() here?
}
}
I know this is a possibility:
interface Base {
fun a()
}
class BaseImpl : Base {
override fun a() {}
fun b() {}
}
class Derived private constructor(private val base: BaseImpl) : Base by base {
constructor() : this(BaseImpl())
fun c() {
base.b()
}
}
But it would be nice if the internally stored object, used for forwarding the Base-methods to, was available without needing to store it explicitly.