Null safety in Kotlin for MutableMap with MutableList
I am trying to run this example
fun main() {
val mlist: MutableList = mutableListOf()
val mapp: MutableMap = mutableMapOf(1 to mlist)
println(mapp)
mapp[1].add("a") // Correct is mapp[1]?.add("a")
println(mapp)
}
at
Online Kotlin Compiler.
The compiler is complaining about Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type MutableList?.
Although I have defined...