case
In Kotlin, the cases of a when <is <type>>...
must be exhaustive only when when
is used as an expression. Wrapping each of the cases in this is an attempt to allow when
to be easily used as an expression even when an expression isn't actually needed. Example:
when(instance) {
is FooNode -> case { ... }
is BarNode -> case { ... }
}.toUnit()
Content copied to clipboard
case returns the sentinel instance of WhenAsExpressionHelper. When used in all cases of a when
and the value is consumed (using the .toUnit()
function, the compiler will enforce that the cases of the when
are exhaustive.