Can anyone explain why this snippet compiles (and ...
# announcements
a
Can anyone explain why this snippet compiles (and executes) without errors? (
get
operator in kotlin is strictly typed)
Copy code
fun main() {
    val intList: List<Int> = listOf(1, 2)
    val stringMap: Map<String, String> = mapOf("abc" to "xyz")
    val x = intList.associateWith { map[it] } // should be an error, because key is String, and not Int
    println(x)
}
Kotlin: 1.4.21
i
It was an error before 1.4, but became a warning due to the new type inference. It will be an error again in 1.5.
a
Ouch
Thank you for the clarification 🙏