thana
04/07/2021, 3:42 PMfun foo () {
val map: NavigableMap<String, String> = TreeMap()
map["key"] = null
}
diesieben07
04/07/2021, 3:47 PMNavigableMap
is a Java class and thus the types become flexibleCasey Brooks
04/07/2021, 3:47 PMset
operator is inlined to .put
, and NavigableMap
is a Java interface so that .put
uses platform typing with no null-safety. If you replace NavigableMap
with MutableMap
, it works as you’d expectMichael Böiers
04/07/2021, 3:47 PMMichael Böiers
04/07/2021, 3:48 PMimport java.util.*
fun foo () {
val map = TreeMap<String, String>()
map["key"] = null
}
thana
04/07/2021, 3:52 PMMichael Böiers
04/07/2021, 3:56 PM