2019年5月20日 星期一

Kotlin學習筆記(11) Null Safety

Kotlin學習筆記(11)  Null Safety


fun main() {
var b: String? = "abc"
b = null // ok
println(b)
   
    val c: String? = "Kotlin"
if (c != null && c.length > 0) {
    println("String of length ${c.length}")
} else {
    println("Empty string")
}
   
    val e: String? = ""
if (e != null && e.length > 0) {
    println("String of length ${e.length}")
} else {
    println("Empty string")
}

}
null String of length 6 Empty string

沒有留言:

張貼留言

2026 作業1 MQTT基本觀念

 2026 作業1MQTT基本觀念 作業  參考下面網址 https://alex9ufoexploer.blogspot.com/2025/02/1-mqtt-relay-dht22-mqtt-box-pc-mymqtt.html https://alex9ufoexploer...