我想知道是否有一种方法可以检查lateinit
变量是否已初始化。例如:
class Foo() {
private lateinit var myFile: File
fun bar(path: String?) {
path?.let { myFile = File(it) }
}
fun bar2() {
myFile.whateverMethod()
// May crash since I don't know whether myFile has been initialized
}
}
allSeries
var 编辑为seriesDir?.listFiles()?.map { it.name }?.toTypedArray()
,这不是很“漂亮”
if (seriesDir != null) {
allSeries = seriesDir.listFiles().map { it.name }.toTypedArray()
}
File?
),然后仅检查它是否为null?