Johann Pardanaud
06/22/2023, 9:48 PM@JvmInline
value class Wrapper(val value: CharSequence) : CharSequence by value
Here, since the inline class and its underlying value both implement the CharSequence
interface, I could write either:
val wrappedValue: CharSequence = Wrapper("foo")
// OR
val wrappedValue: CharSequence = "foo"
But, in the first case, the value seems to be boxed:
@NotNull
private static final CharSequence wrappedValue = Wrapper.box-impl(Wrapper.constructor-impl((CharSequence)"foo"));
There is probably a reason, but I don't get it. 🤔Johann Pardanaud
06/22/2023, 9:49 PMJohann Pardanaud
06/22/2023, 10:00 PMfun someFun(): Set<List<String>>
I would like to provide something a bit more readable:
fun someFun(): Set<ExplicitType>
Since I need the collections, should I go with a type alias instead of an inline class?ephemient
06/22/2023, 10:11 PMJohann Pardanaud
06/22/2023, 10:23 PMephemient
06/22/2023, 10:30 PMwrappedValue is Wrapped
evaluates differentlyephemient
06/22/2023, 10:32 PMJohann Pardanaud
06/22/2023, 10:33 PMJohann Pardanaud
06/22/2023, 10:41 PMJoffrey
06/22/2023, 10:41 PMephemient
06/22/2023, 11:00 PMAny
which is special) but yesStephan Schröder
06/23/2023, 12:27 PMJohann Pardanaud
06/23/2023, 12:40 PMfun main() {
val list = listOf(Wrapper("foo"))
val second = list.first()
val third = listOf(second)
}
Generates:
List list = CollectionsKt.listOf(Wrapper.box-impl(Wrapper.constructor-impl("foo")));
String second = ((Wrapper)CollectionsKt.first(list)).unbox-impl();
List third = CollectionsKt.listOf(Wrapper.box-impl(second));
You can see it boxes, unboxes, and boxes again.Johann Pardanaud
06/23/2023, 12:40 PM