|
A simple enum can be be defined concisely.
|
|
|
It is also possible to have enum classes with properties and constructors.
|
enum class Color(val rgb: Int) {
|
|
It is also possible to add computed properties or methods. The list of enums must be separated from the members with a semicolon.
|
enum class BetterColor(val rgb: Int) {
val g = (rgb shr 8) and 0xff;
|
|
Another more advanced variant is to implement the members as instances of anonymous classes.
|
enum class ProtocolState {
override fun signal() = TALKING
override fun signal() = WAITING
abstract fun signal(): ProtocolState
val north = Direction.NORTH
val moreRed = BetterColor.RED
var ps = ProtocolState.WAITING
|