# getting-started

Kshitij Patil

10/06/2023, 8:09 AM
Can we do this? sealed with value classes
Copy code
sealed interface Color {
    value class StringColor(val value: String) : Color
    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

Adam S

10/06/2023, 8:33 AM
Your code will work, but yes, autoboxing can always happen. I really like this guide for explaining when autoboxing happens 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!

Kshitij Patil

10/06/2023, 8:39 AM
But we’re not gaining anything with value class either