Nullable value ကိုအသုံးပြုတဲ့အခါ crash မဖြစ်အောင် safe call operator ?. နဲ့ Elvis operator ?: ကိုသုံးပါတယ်။ ဒီနှစ်ခုကိုနားလည်ထားရင် API response, optional user profile data, database field တွေကိုပိုလုံခြုံစွာကိုင်တွယ်နိုင်ပါတယ်။
kotlin
fun main() {
val name: String? = null
val length = name?.length
println("Length: $length")
val displayName = name ?: "Guest User"
println("Welcome, $displayName")
}You should see
Length: null Welcome, Guest Userအနှစ်ချုပ်
Nullable value ကိုတိုက်ရိုက်မကိုင်ပါနဲ့။ ?. နဲ့ ?: ကိုသုံးပြီး safe path ပြုလုပ်ပါ။