Folks, is there a better way to do this? ``` val p...
# getting-started
m
Folks, is there a better way to do this?
Copy code
val pickableState = try {
            PickableState.valueOf(state)
        } catch (ex: Exception){
            null
        }
m
you could encapsulate this boilerplate in a generic function:
Copy code
inline fun <reified E : Enum<E>> enumValueOrNull(name: String): E? = try {
    enumValueOf<E>(name)
} catch (e: Exception) {
    null
}
👍 1
✔️ 1