一、错误代码
private var nameList:MutableList<Any>?=null
fun testList(){
nameList = mutableListOf()
nameList.add(Any())
}
在nameList.add(Any()) 处报错,报错信息:
Smart cast to 'XXX' is impossible, because 'XX' is mutable property that have been changed by this time
二、解决办法
IDEA提示信息错误,光标移至报错处,按"shift+enter"自动修复,添加非空检测。