https://kotlinlang.org logo
Title
b

bdawg.io

01/30/2018, 1:03 AM
enum valueOf method Am I able to modify the behavior of an enum’s
valueOf
? Or will it only ever consider the
name
property on the specified enum?
t

tateisu

01/30/2018, 11:17 AM
you can add extra parameter.
enum class X(val num:Int){ A(1),B(2),C(3) }
fun main(args:Array<String>){
    println( X.values().first{ it.name =="C"})
    println( X.values().first{ it.num==2})
}
b

bdawg.io

01/30/2018, 6:18 PM
That doesn’t change the behavior of
valueOf(...)
though, that requires you to iterator over
values()
t

tateisu

01/31/2018, 10:11 AM
I believe valueOf() also iterate names.