标签:span code ack bsp class return print tor const
package loaderman.demo enum class EnumClass private constructor(val d:Int){ A(1),B(2),C(3),D(4); override fun toString(): String{ return d.toString() } }
package loaderman import loaderman.demo.EnumClass fun main(arg: Array<String>) { val a = EnumClass.A println(a) }
输出:1
package loaderman import loaderman.demo.EnumClass fun main(arg: Array<String>) { val a = EnumClass.A val name = EnumClass.A.name//枚举值名字 val index = EnumClass.A.ordinal//枚举值名索引 0开始 println(a) println(EnumClass.valueOf("A"))//通过valueOf方法传入枚举值名称获取枚举值对应的数值 println(name) println(index) }
标签:span code ack bsp class return print tor const
原文地址:https://www.cnblogs.com/loaderman/p/10126887.html