The most basic usage of *enum* classes is implementing [_type-safe enums_, like in *Java*|http://www.javacamp.org/designPattern/enum.html]:
{jet}
enum class Direction {
  NORTH; SOUTH; WEST; EAST
}
{jet}
As everywhere in [Kotlin], one can omit semicolons if each enum constant is situated on its own line:
{jet}
enum class Direction {
  NORTH
  SOUTH
  WEST
  EAST
}
{jet}

{note:title=Enums are under development}See the corresponding [issues|http://youtrack.jetbrains.com/issues/KT?q=%23unresolved+enum].{note}

h4. Open enums

In [Kotlin] *enums* can be *open*, i.e. can be subclassed by other enums:
{jet}
open enum class OptionKeys {
  OPTION1
}
enum class ExtraOptionKeys : OptionKeys {
  OPTION2
}
fun demo() {
  ExtraOptionKeys.OPTION2 : ExtraOptionKeys // legal
  ExtraOptionKeys.OPTION1 : OptionKeys // legal
  OptionKeys.<unresolved desc="Unresolved symbol">OPTION2</unresolved> // error: OPTION2 is not a member of OptionKeys
}
{jet}
Enums can extend other enums and traits as well.

h4. Enums constants are objects

Since enum constants are different instances of the *enum class*, they can be initialized differently:
{jet}
enum class Color(val rgb : Int) {
  RED : Color(0xFF0000)
  GREEN : Color(0x00FF00)
  BLUE : Color(0x0000FF)
}
{jet}

h4. Enum constants define (anonymous) classes

Each enum constant may declare its own members and override members of the *enum class*:
{jet}
enum class ProtocolState {
  WAITING {
    override fun signal() = TALKING
  }

  TALKING {
    override fun signal() = WAITING
  }

  abstract fun signal() : ProtocolState
}
{jet}

h4. Constructors in enum classes

Enum classes actually encode (generalized) Algebraic Data Types, and thus may have _named constructors_ instead of constants:
{jet}
enum class List<out T>(val size : Int) {
  Nil : List<Nothing>(0)
  Cons<T>(h : T, t : List<T>) : List<T>(t.size + 1)
}
{jet}

h4. Pattern matching

Enums classes are integrated with [pattern matching|Pattern matching]:
{jet}
fun List<String>.join(separator : String) =
  when (this) {
    is List.Nil -> "[]"
    is List.Cons#(val h, val tail) -> h + separator + tail.join(separator)
  }
{jet}

h3. What's next

* [Nested classes]
* [Object expressions and Declarations]