Colton Idle
11/17/2022, 6:34 AMval buttonText = when (MyEnum.values() == myString) {
ONE -> "first case"
TWO -> "second case"
else -> "Your string does not match any of the enums"
}
Colton Idle
11/17/2022, 6:38 AMval buttonText = when (MyEnum.valueOf(myString)) {
ONE -> "first case"
TWO -> "second case"
else -> "Your string does not match any of the enums"
}
ephemient
11/17/2022, 6:42 AMvalueOf
throws IAE on invalid inputColton Idle
11/17/2022, 6:42 AMColton Idle
11/17/2022, 6:43 AMephemient
11/17/2022, 6:43 AMephemient
11/17/2022, 6:45 AMColton Idle
11/17/2022, 6:45 AMColton Idle
11/17/2022, 6:45 AMinline fun <reified T : kotlin.Enum<T>> safeValueOf(type: String?): T? {
return java.lang.Enum.valueOf(T::class.java, type)
}
looks like i can add thatephemient
11/17/2022, 6:46 AMephemient
11/17/2022, 6:47 AMtry {
MyEnum.valueOf(string)
} catch (_: IllegalArgumentException) {
null
}
Colton Idle
11/17/2022, 6:47 AMColton Idle
11/17/2022, 6:47 AMColton Idle
11/17/2022, 6:50 AM