Kotlin Enum
Summarize of Kotlin Enum
6. Enum
1. Initialization
Enum classes as any other classes can have a constructor and be initialized
1 | enum class Color (val rgb: Int){ |
2. Simple Enum
1 | enum class Color2{ |
Each enum constant is an object. Enum constants are separated with commas.
3. Mutability
Enums can be mutable, this is another way to obtain a singleton behavior:
1 | enum class Color3(var x : Int = 0){ |
1 | var c = Color3.MARS |