DEV Community

Discussion on: NULL, "The Billion Dollar Mistake", Maybe Just Nothing

Collapse
 
fxedel profile image
Felix Edelmann • Edited

When we talk about null, we should also talk about Kotlin and its null-safety.

First of all, all types (Int, String, ...) are non-null by default. If you want to allow null for a certain variable, you use the nullable type (Int?, String?, ...).

When dealing with nullable variables, one can use the Elvis operator:

val name: String? = customer?.name
Enter fullscreen mode Exit fullscreen mode

name will be either a String or null if customer or customer.name is null. It won't throw if customer is null.

Collapse
 
joelnet profile image
JavaScript Joel • Edited

Non-null by default is the way it should be. I have never used Kotlin, but it sounds like they are doing things right.

I also love the term Elvis Operator!

Elvis Operator