https://kotlinlang.org logo
Title
e

edwardwongtl

01/23/2018, 10:32 AM
And the compiler knows exactly how many child class it has
b

Benoît

01/23/2018, 10:33 AM
How can that be helpful ?
m

menegatti

01/23/2018, 10:33 AM
when
cases. By knowing what are the possible children of a class, you can be sure that the when will be comprehensive
it is mentioned at the bottom of the documentation
e

edwardwongtl

01/23/2018, 10:35 AM
Exactly, it helps the compiler to warn you that you havn't handle all possible cases
b

Benoît

01/23/2018, 10:37 AM
Cheers guys
a

aidanvii

01/23/2018, 10:39 AM
It’s useful when you wan’t enum-like behaviour, where some ‘values’ (child classes in the case of sealed classes) may have state, some may not have state and can be defined as
object
singletons, similar to standard enums.
e

edwardwongtl

01/23/2018, 10:54 AM
I would say
selaed class
is a more powerful version of
Enum