January 2018
Intermediate to advanced
434 pages
14h 1m
English
When we are sure that a value or a class can have only a limited set of types or number of subclasses, that's when we try to restrict class hierarchy. Yes, this might sound like an enum class but, actually, it's much more than that. Enum constant exists only as a single instance, whereas a subclass of a sealed class can have multiple instances that can contain state. Let's look at an example in the mentioned steps:
class ShowMessageToast(val message:String):ToastOperation()
object ShowErrorToast:ToastOperation()
Read now
Unlock full access