Please direct me to the right channel, but here’s ...
# getting-started
e
Please direct me to the right channel, but here’s the question:
Copy code
// this delegation works

interface A { fun foo() }
interface B { fun bar() }

class AImpl() : A { override fun foo() = println("default foo") }
class BImpl(private val a: AImpl) : B, A by a { override fun bar() = println("bar") }

// ==============

// how could I do a delegation for an inherited interface?
interface A { fun foo() }
interface B : A { fun bar() }

class AImpl() : A { override fun foo() = println("default foo") }
// no idea how to delegate
class BImpl(private val a: AImpl) : B by a { override fun bar() = println("bar") } // ?
r
Copy code
class BImpl(private val a: AImpl): B, A by a { ... }
e
I think what I’m looking for here is partial interface implementation delegation
not sure if it’s possible in Kotlin at all
r
Why? The example I gave did exactly what you asked, and it is way less cryptic/confusing.
e
I don’t want
BImpl
to have an explicit inheritance from
A
, I’d like to achieve that through
B
if possible. And therefore, a partial delegation would be required
r
But that's not what the
a
parameter is.
s
yeah, I'm with Ruckus. Inheritance is explicit in Kotlin (in order for
BImpl
to implement
A
, it has to be explicit about it). Ruckus' solution to generate default proxy calls to a parameter is as close as you can get to what you want.
e
thanks for the feedback. I discussed this in the language propoosals channel as well: https://kotlinlang.slack.com/archives/C0B9K7EP2/p1632516626019100