Hello 👋
I'm wondering why these two compile:
private inline fun <reified K, reified V> JsonElement.decodeOne(key: String): Map<K, V> {
return jsonObject[key]
?.let { Json.decodeFromJsonElement<Map<K, V>>(it) }
.orEmpty()
}
private fun <K, V> JsonElement.decodeOne(key: String): Map<K, V> {
return jsonObject[key]
?.let { Json.decodeFromJsonElement<Map<K, V>>(it) }
.orEmpty()
}
but only the first one works at runtime.
Wouldn't it be possible to check this at compile time. The same way it's done (screenshot) for
Json.decodeFromJsonElement<K>(smth)
when
K
is generic, but not reified.
Or is type-erasure still a problem here?