Stage 1 · Lesson 2 of 9
Null safety
In a String can never be null; only a String? can. This means the compiler makes you handle the missing case. Learn the tools in order.
First an if (name != null) check, after which Kotlin smart casts, treating the value as a plain String. Then safe calls with ?., the elvis operator ?: for a default, and ?.let { } to run code only when a value exists. Values coming from code have platform types that Kotlin cannot check, so treat them as nullable.
Smart casts do not work on a var property that could change between the check and the use.
Common trap!!, which says "trust me" and throws a NullPointerException when you were wrong.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeKotlin Documentation
JetBrains
Start with the Kotlin tour, then the null safety and coroutines basics pages
- CourseFreeAndroid Basics with Compose
Google · Beginner
The Kotlin pathways in Units 1 to 3 teach the language with practice sets