Advanced Usage of Enum Classes

Learn to define enum classes with primary constructors, immutable values, and abstract methods.

Enum classes with primary constructors

In Kotlin, each enum value can hold a state. It is possible to define a primary constructor for an enum class, and then each value needs to specify its data next to its name.

Tip: It is a best practice that enum values should always be immutable. Therefore, their state should never change.

Get hands-on with 1200+ tech skills courses.