Steven McLaughlin
10/22/2018, 5:47 PMBAD
into that function? Essentially, I want to make the when block exhaustive but not change the behavior of the function.
enum class SomeEnum {
GOOD,
BAD
}
fun doTheEnumThing(someEnum: SomeEnum) {
when (someEnum) {
SomeEnum.GOOD -> println("good")
}
}
Ruckus
10/22/2018, 5:52 PMfun doTheEnumThing(someEnum: SomeEnum) {
if (someEnum == SomeEnum.GOOD) {
println("good")
}
}
There's no else statement, so nothing happens. It just returns.Steven McLaughlin
10/22/2018, 5:53 PMwhen (someEnum) {
SomeEnum.GOOD -> println("good")
SomeEnum.BAD -> return
}
Ruckus
10/22/2018, 5:55 PMSomeEnum.BAD -> Unit
// or
SomeEnum.BAD -> {}
pavel
10/22/2018, 5:55 PMRuckus
10/22/2018, 5:56 PMpavel
10/22/2018, 5:56 PMSteven McLaughlin
10/22/2018, 5:56 PMRuckus
10/22/2018, 5:57 PMSomeEnum.BAD -> Unit // Do Nothing
// or
SomeEnum.BAD -> {} // Do Nothing
cedric
10/22/2018, 8:18 PMwhen
is a value for an expression, the compiler will mandate exhaustiveness