snowe
04/09/2019, 8:25 PMincomeTypes.forEach {
val incomeType = IncomeType.valueOf(it, IncomeType.UNKNOWN)
Pavlo Liapota
04/09/2019, 8:57 PMenumConstants.firstOrNull { it.name == name } ?: default
snowe
04/09/2019, 8:58 PMinline fun <reified T: Enum<T>> String.enumWithDefault(defaultValue: T) : T {
return try{
enumValues<T>().first {it.name == this }
} catch (e: NoSuchElementException) {
defaultValue
}
}
or inline fun <reified T : Enum<T>> enumValueOf(name: String, defaultValue: T): T {
return try {
enumValues<T>().first { it.name == name }
} catch (e: NoSuchElementException) {
defaultValue
}
}
to the dev.Burkhard
04/09/2019, 10:28 PMfirstOrNull { it.name == name } ?: default
. Creating Exceptions is quite expensive, because of the generated stack trace.snowe
04/10/2019, 3:51 PMBurkhard
04/10/2019, 3:55 PMsnowe
04/10/2019, 4:08 PM