🐦 Kotlin Beginner

What is an enum class in Kotlin?

Answer

An enum class defines a type with a fixed set of named constants, each of which is a singleton instance of the enum class. Example: enum class Direction { NORTH, SOUTH, EAST, WEST }. Unlike Java, Kotlin enums can have properties and methods: enum class Color(val hex: String) { RED("#FF0000"), GREEN("#00FF00") }. When used in a when expression, Kotlin can verify exhaustiveness — if you cover all enum values, you do not need an else branch. Prefer sealed classes when you need instances with different properties per variant.