默认属性 | oridinal | 该枚举常量的顺序,从0开始 |
name | 该枚举常量的名字 | |
默认函数 | values( ) | 获取所有枚举常量 |
valueof( ) | 获取对应枚举常量 |
enum class Demo {
RED, BLUE, YELLOW, GREEN
}
println(Demo.BLUE.ordinal) //打印:1
println(Demo.BLUE.name) //打印:BLUE
val aa = Demo.valueOf("GREEN")
Demo.values().forEach { print( "$it,") } //打印:RED,BLUE,YELLOW,GREEN,