Stylianos Gakis
04/10/2024, 12:04 PMMyEnum.valueOf(someString)
to get an enum from its String representation, what is the equivalent when using the new entries
field?
Is it perhaps MyEnum.entries.first { it.name == someString }
? With firstOrNull
being a safe alternative to it? Or am I missing something?dmitriy.novozhilov
04/10/2024, 12:14 PMvalueOf(name)
entries
is a replacement for values()
, not for valueOf
dmitriy.novozhilov
04/10/2024, 12:16 PMentries + firstOrNull
instead of valueOf + catch (e: IllegalArgumentException)
Stylianos Gakis
04/10/2024, 12:21 PMvalueOf()
. And if I can avoid a try/catch I’m more than happy to do so.
Thanks a lot for the help!ephemient
04/10/2024, 4:14 PM