enum valueOf method Am I able to modify the behavi...
# getting-started
b
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
you can add extra parameter.
Copy code
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
That doesn’t change the behavior of
valueOf(...)
though, that requires you to iterator over
values()
t
I believe valueOf() also iterate names.