Why does Interface Delegation only support delegating to constructor arguments?

Many classes have zero-argument constructors, but could still benefit from delegating an interface to some val.

Notably, AFAICT it is impossible for an object to delegate an interface, since objects do not have constructors.

Sometimes you can work around this restriction using private constructors, but objects cannot do this.

It seems like an arbitrary restriction.

1 Like

Maybe I’m oversimpifying but if a class has zero-arg constructors, then all of its instances are identical, therefore the values they contain are actually globals.
And you can delegate to a global, the following code is legal:

interface Interface
object Foo : Interface
object Bar : Interface by Foo

Also could you provide a concrete example of this? Delegation is useful when you’re wrapping some existing object and somehow combine that with other functionality. I can’t imagine that happening in an interesting way with singletons.