Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created February 2, 2020 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/1f5e6beb5e6547d2fa438407c983db2b to your computer and use it in GitHub Desktop.
Save magdamiu/1f5e6beb5e6547d2fa438407c983db2b to your computer and use it in GitHub Desktop.
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