我遇到了Kotlin类型系统的问题.我在类范围声明了变量如下:
var planets: ArrayList<Planet>? = null
Run Code Online (Sandbox Code Playgroud)
并在构造函数中我尝试初始化数组但我遇到类型不匹配错误:
planets = arrayListOf(earth, mars, saturn, jupiter, uranus, neptune, pluto)
Run Code Online (Sandbox Code Playgroud)
错误:
Required: ArrayList<Planet>?
Found: ArrayList<Planet?>
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误,如何解决?
kotlin ×1