The key benefit of using sealed classes comes into play when you use them in a when expression. If it’s possible to verify that the statement covers all cases, you don’t need to add an else clause to the statement.
But that seems not to be true, since this examples compiles without any error or warning:
sealed class Direction
object Left : Direction()
object Right : Direction()
fun main(args: Array<String>) {
decide(Right)
}
fun decide(direction: Direction) {
when(direction) {
is Left -> println("L")
//is Right -> println("R")
}
}
I tried it with Kotlin 1.2-M1.
What is wrong: my code, the documentation or the compiler?