I was reading the documentation of sealed classes https://kotlinlang.org/docs/reference/sealed-classes.html
sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr()
Like the example code, why do we put the parentheses for the case of sealed classes,
: Expr(), unlike normal classes where we would write
: Expr ?
Expr() mean instantiating the class? If this is the case, it would contradict to the sentence from the documentation
A sealed class is abstract by itself, it cannot be instantiated directly and can have abstract members.
I also don’t understand why here
Sum(val e1: Expr, val e2: Expr) : Expr()
e2 we write
: Expr while for class
Sum we write
How should I understand this, and what’s happening under the hood?
I discovered that the use of parentheses is not only limited to the case of sealed classes.
How should I understand the parentheses?