Skip to content

Instantly share code, notes, and snippets.

@PragmaticCoding
Last active November 26, 2021 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PragmaticCoding/5059ba75f5b94a77e2ea406f0814f24d to your computer and use it in GitHub Desktop.
Save PragmaticCoding/5059ba75f5b94a77e2ea406f0814f24d to your computer and use it in GitHub Desktop.
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