Hello :wave: I'm wondering why these two compile: ```private inline fun <reified K, reified V&g...
m
Hello 👋 I'm wondering why these two compile:
Copy code
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()
}
Copy code
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?
Forgot to attach the exception I'm getting at runtime (2nd impl):
Copy code
Function 'decodeOne$lambda-0' (JVM signature: decodeOne$lambda-0(Lkotlinx/serialization/json/JsonElement;)Ljava/util/Map;) not resolved in class com.somepackage.Decoder: no members found