Marko Mitic
09/03/2019, 11:06 AMsuspend inline fun <reified T> get(key: String): T? =
dao.getById(key)?.let {
when (T::class) {
String::class -> it.value as T
Int::class -> it.value.toInt() as T
Float::class -> it.value.toFloat() as T
Double::class -> it.value.toDouble() as T
else -> throw IllegalArgumentException("Not implemented for the given type.")
}
}
spand
09/03/2019, 11:24 AMMarko Mitic
09/03/2019, 11:27 AMelizarov
09/03/2019, 1:47 PMMarko Mitic
09/04/2019, 11:27 AMfun b(): String = when(String::class){
Int::class -> "1"
String::class -> "2"
else -> "0"
}
Kinda silly example but one might expect compiler to optimize it to fun b() = "2"