Daniel Svensson
10/05/2021, 11:35 AMvalue class WriteableResource(val ro: Resource)
to a method only accepting Resource
without explicitly passing its member? Does it have to explicitly implement an interface for Resource
?Daniel Svensson
10/05/2021, 11:40 AMinterface I
@JvmInline
value class Foo(val i: Int) : I
fun asInterface(i: I) {}
val f = Foo(42)
asInterface(f) // boxed: used as type I
Daniel Svensson
10/05/2021, 11:49 AMthanksforallthefish
10/05/2021, 11:59 AMclass WriteableResource(val ro: Resource) : Resource by ro
and you can then pass it to all methods accepting a Resource
.
but this syntax is not supported by value
classesDaniel Svensson
10/05/2021, 12:10 PMDaniel Svensson
10/05/2021, 12:11 PMDaniel Svensson
10/05/2021, 12:12 PMthanksforallthefish
10/05/2021, 12:18 PMDaniel Svensson
10/06/2021, 7:16 PMthanksforallthefish
10/07/2021, 6:01 AMCurrently, we should either save the result of expr somewhere...
kinda obvious why delegation for inlined classes is not âpossibleâ, since inlined classes disappear at runtime I see how it would require workarounds. and given the change to value
class gives a better semantic to what a value class should be for (imo, no behavior, just data) it probably makes sense to forbid a more behavior-oriented pattern such as delegation