📅  最后修改于: 2022-03-11 14:53:33.625000             🧑  作者: Mango
You can fix this by calling toMutableList() api
rather than using smart cast (as).
fun main(){
val x : List = listOf("foo", "bar", "baz")
//val y: MutableList = x as MutableList throws UnsupportedOperationException
val y: MutableList = x.toMutableList()
y.add("sha")
println(y) // [foo, bar, baz, sha]
}