Kotlin判断null比较let布尔值Boolean
Kotlin
class MyData {
val count: Int? = 2023
val number: Int? = null
}
fun main(args: Array<String>) {
val data = MyData()
val year = 2022
if (data.count != null) {
if (data.count > year) {
println("data.count != null")
}
}
if (data.count!! > year) {
println("data.count!!")
}
var b1 = data.count?.let { it > 2022 } ?: false
println(b1)
var b2 = data.number?.let { it > 2022 } ?: false
println(b2)
var b3 = data.count?.let { it > 9999 } ?: false
println(b3)
}
data.count != null
data.count!!
true
false
false