Given ```sealed interface Parent { data class Ch...
# random
s
Given
Copy code
sealed interface Parent {
  data class Child1(val value: String): Parent
  data object Child2 : Parent
}
Am I the only one who prefers
Copy code
when (parent) {
  is Parent.Child1 -> // ...
  is Parent.Child2 -> // ...
}
over
Copy code
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
.
➕ 1
y
data 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 same
s
Would actually be nice if we could configure IDEA's “fill in the
when
cases” to always include the
is
cases like these.