Arkadii Ivanov
02/10/2024, 3:02 PMinterface Foo {
fun foo1()
fun foo2()
}
class FooImpl : Foo {
override fun foo1() { /*...*/ }
override fun foo2() { /*...*/ }
}
class Bar private constructor(
private val foo: Foo, // Private constructor as we don't want to expose the parameter
) : Foo by foo {
constructor() : this(foo = FooImpl())
override fun foo1() {
foo.foo1()
// Additional code here
}
}
It would be good to have something like this instead.
class Bar : Foo by foo@FooImpl() {
override fun foo1() {
foo.foo1()
// Additional code here
}
}
Rob Elliot
02/10/2024, 4:09 PMclass Bar : Foo by foo {
private val foo = FooImpl()
override fun foo1() {
foo.foo1()
// Additional code here
}
}
Arkadii Ivanov
02/10/2024, 4:37 PM