Tony Hoare called the null reference his "billion-dollar mistake," and Kotlin's answer is to build null safety into the type system. A regular type like String can never hold null, and a type that can is marked explicitly with a question mark, as in String?. The compiler then refuses to let you use a nullable value unsafely, which removes most NullPointerExceptions before the program ever runs.
This module covers the tools for working with nullable values: the safe call operator (?.), the Elvis operator (?:) for default values, and the non-null assertion (!!) and why to use it sparingly. You'll also learn smart casts, where the compiler tracks type checks for you, and safe casts with as?, so you can handle types confidently.
Watch the lessons in order, then continue on to Functions & Lambdas.
A beginner-friendly introduction to Kotlin's null safety and smart casts, and how they help you write more robust code.
Covers the safe call operator, using let with nullable values, the Elvis operator, and the non-null assertion operator.
Shows how the Elvis operator returns a fallback value when an expression is null, and how safe calls chain through nullable values.
Best practices for handling nullability effectively with safe calls and the Elvis operator, to avoid null bugs in real code.