OK, now that Kotlin is officially out and I am starting to play with it again, I am quite confused that I need to choose between the advantages of sealed
and data
but somehow can't have both.
This, for example, seems to make sense to me, but does not compile:
sealed class Expr {
data class Const(val number: Double) : Expr()
data class Sum(val expr1 : Expr, val expr2 : Expr) : Expr()
}
because the data classes cannot extend other classes.
Is there something I am missing?