Apologies if this was already discussed earlier, I...
# language-proposals
a
Apologies if this was already discussed earlier, I couldn't find any related messages or YT tickets. Let me know if there is one. When using interface delegation, it would be good to have easier access to the implementing object from inside the class. Currently this can be done as follows, which is pretty verbose:
Copy code
interface 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.
Copy code
class Bar : Foo by foo@FooImpl() {
    override fun foo1() {
        foo.foo1()
        // Additional code here
    }
}
r
I think you're looking for this proposal: https://youtrack.jetbrains.com/issue/KT-2747/Delegation-specifier-fails-to-refer-to-val-property-which-is-not-constructor-parameter Which would allow:
Copy code
class Bar : Foo by foo {
    private val foo = FooImpl()

    override fun foo1() {
        foo.foo1()
        // Additional code here
    }
}
a
Thank you!