sindrenm
08/19/2026, 12:14 AMsealed interface Parent {
data class Child1(val value: String): Parent
data object Child2 : Parent
}
Am I the only one who prefers
when (parent) {
is Parent.Child1 -> // ...
is Parent.Child2 -> // ...
}
over
when (parent) {
is Parent.Child1 -> // ...
Parent.Child2 -> // ...
}
?
I guess there might be a slight performance implication (instanceof vs == on Child2), but (1) it's so much more pleasant to read when the cases are aligned, and (2) if I ever were to make Child2 a class, then I wouldn't need to add an is.Youssef Shoaib [MOD]
08/19/2026, 12:32 AMdata object compares using instanceof anyway, so there's no perf difference (well, == probably has a === fast-path check, but there's no way that matters much).
I like the consistency of is, so I tend to do the samesindrenm
08/19/2026, 1:01 AMwhen cases” to always include the is cases like these.