If I have a Kotlin enum
enum class Opcode { unsubscribe }
and I have a String s == “unsubscribe”, how do I get an Opcode given this string? In Java I would do
Opcode o = Opcode.valueOf(s)
If I have a Kotlin enum
enum class Opcode { unsubscribe }
and I have a String s == “unsubscribe”, how do I get an Opcode given this string? In Java I would do
Opcode o = Opcode.valueOf(s)
I've come up with this, but I was hoping for something more compact:
if( args[t].equals("--opcode")) { val oc = args[++t] when (oc) { "unsubscribe" -> opcode = Opcode.unsubscribe else -> { throw RuntimeException("invalide opcode ${oc}") } } }
Unfortunately, this syntax is not supported yet. I have created request in our issue tracker: KT-1517
Thanks!