Interface delegation in interfaces would be nice :...
# language-proposals
m
Interface delegation in interfaces would be nice 🙂 Using default implementations.
Copy code
interface Foo {
	fun foo()
}

interface FooDecorator : Foo by decorated {
	val decorated: Foo
}
👍 1
j
imho delegation should be bifurcated by some keyword that chooses which vtable intercepts the delegate's methods. the current delegation bypasses the declaring class which costs the same work as delegates in pure java, to write manual accessors to pass into the delegate. otherwise you get wormholes in the declaring class vtable that send calls and call state on a one way trip with no parent reference
`class SkipList (cpy:ArrayList) : List by cpy`` if i delegate List with a SkipList class, i may have statechange in List that has no way to update methods in SkipList. List.size goes to the delegate not the SkipList declaring class for instance.
Skiplist has a size member, but if List delegate needs to know size, it may not access Skiplist size.
j
you can just do a normal override for that
m
Sure I can. I could do the same with normal delegation. The point of delegation is not having to implement and delegate every method individually, isn't it? 🤔
j
Sorry I don't mean you. I agree with your proposal and I believe there's a tracking issue for it.
m
Ah okay, sorry then 🙏
j
I suspect Andrey's dislike of interface delegation is why it hasn't seen any improvements, although I'm not clear on exactly what/how it would be improved if designed from scratch. In any case. please file a bug. I would vote!
👍 1
j
you can just do a normal override for that
you cannot inherit from a parameter, but you may benefit from delegating to it. but if you want to have coherence by parent dispatch, you would have to override and manually write the same methods as in java.