Derek Peirce
06/28/2023, 4:42 PMclass Foo: Bar by bar {
val bar: Bar = ...
}
This would get Unresolved reference: bar
. Is there any reasoning for this other than the order in which the compiler is evaluating symbols? Could the compiler be improved so that it understands that bar
exists, and generates the proper delegation code?
override fun doBar() = bar.doBar()
I'd also like to see the ability to delegate by method instead of by entire interface, something like:
override fun doBar() by bar
with specifying the arguments being optional, otherwise all possible overloads are delegated.Rob Elliot
06/28/2023, 4:44 PMDerek Peirce
06/28/2023, 4:47 PMuli
09/28/2023, 7:53 PMval bar
as constructor parameter with default value?
interface Bar
object BarInstance: Bar
class Foo private constructor(val bar: Bar = BarInstance) : Bar by bar
Or to a private constructor making only a secondary constructor without `bar`public?
interface Bar
object BarInstance: Bar
class Foo private constructor(val bar: Bar) : Bar by bar {
constructor() : this(bar = BarInstance)
}
uli
09/28/2023, 8:00 PMRob Elliot
09/28/2023, 8:03 PMuli
09/29/2023, 7:52 AMbarFactory:: ()->Bar
and delegate to barFactory()
. But barFactory
is only evaluated once at initialization time.Rob Elliot
09/29/2023, 10:10 AM