Julia Samól
04/28/2022, 10:50 AMinterface I
@JvmInline
value class A(val instance: I) : I by instance // Error: Value class cannot implement an interface by delegation if expression is not a parameter
and I’m wondering whether value classes lack that feature or I’m the one missing something hereJhonatan Sabadi
04/28/2022, 11:32 AMvalue class Age (value: Int)
val age = Age(10)
At compile time will be replaced by val age: Int = 10
Julia Samól
04/28/2022, 12:58 PMinterface I {
fun foo()
}
@JvmInline
value class A(val instance: I) : I by instance
or
interface I {
fun foo()
}
@JvmInline
value class A(val instance: I) : I {
override fun foo() {
instance.foo()
}
}
The goal here is to ensure on the type level a “deeper meaning” of some I
instances but also not to lose the perks of the I
interface, and the last time I checked it seems to work as expected, the underlying instance
doesn’t get boxed when foo
is called on A
.Jhonatan Sabadi
04/28/2022, 1:20 PMJulia Samól
04/28/2022, 1:53 PMString
is not a primitive type on JVM, also take a look at the Result
implementation, please. It’s inline and takes Any?
as the parameter.Julia Samól
07/05/2022, 8:29 AM