Created
February 2, 2020 14:59
-
-
Save magdamiu/1f5e6beb5e6547d2fa438407c983db2b to your computer and use it in GitHub Desktop.
Enum in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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