Skip to content

Enum compared with sealed classes

Devrath edited this page Aug 9, 2022 · 2 revisions
Enum SealedClasses
Enum classes represent a concrete set of values sealed classes represent a concrete set of classes
They are perfect to represent a constant set of possible values They are great to define a set of events or messages that might occur
The advantage of enum classes is that they can be serialized and deserialized out of the box. They have methods valueOf, values which are easy to iterate The advantage of sealed classes is that they can hold instance-specific data
Clone this wiki locally