非空调用

This commit is contained in:
luming 2021-06-29 13:51:16 +08:00
parent ed929baed7
commit 90be696c18

View File

@ -99,4 +99,13 @@ fun main() {
it == 6L it == 6L
} }
println(index) println(index)
// 可空变量
var str: String? = null
// 安全调用符
println(str?.length)
// 默认值
println(str?.length ?: "默认值")
// 非空断言 为空 运行时抛空指针异常
println(str!!.length)
} }