Last active
November 26, 2021 22:00
-
-
Save PragmaticCoding/5059ba75f5b94a77e2ea406f0814f24d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun handleNullable() { | |
val customer: Customer? = database.fetchCustomer(customerId) | |
val customerName:String = customer?.let{it.getName()}?: "Mr. Nobody" | |
println("The customer name is $customerName") | |
} | |
fun betterHandleNullable() { | |
println("The customer name is " + database.fetchCustomer(customerId)?.name ?: "Mr. Nobody") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment