Can we do this? sealed with value classes ```seale...
# getting-started
k
Can we do this? sealed with value classes
Copy code
sealed interface Color {
    @JvmInline
    value class StringColor(val value: String) : Color
	@JvmInline
    value class IntColor(val value: Int): Color
}
👌 1
Was trying to avoid boxing-unboxing. It appears sealed & value classes are negating each other and boxing happens nonetheless. So no point doing this it seems
a
Your code will work, but yes, autoboxing can always happen. I really like this guide for explaining when autoboxing happens https://typealias.com/guides/inline-classes-and-autoboxing/ To best avoid autoboxing you'd want something like a single Color value class, but with multiple constructors for string/int values. But what you've written works fine too, and autoboxing is unlikely to be a big problem, so I'd be more cautious about preoptimising!
k
But we’re not gaining anything with value class either