Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created Feb 2, 2020
Embed
What would you like to do?
Enum in Kotlin
enum class Color(val value: Int) {
GOLD(0xffd323),
SILVER(0xeaeaea),
WHITE(0xffffff),
BLACK(0x000000),
RED(0xFF0000)
}
fun printProperty() = println(Color.GOLD.value) // => 16765731
fun printName() = println(Color.GOLD.name) // => GOLD
fun printPosition() = println(Color.GOLD.ordinal) // => 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment