re: NULL, "The Billion Dollar Mistake", Maybe Just Nothing VIEW POST


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

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


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

code of conduct - report abuse