Let's think about it for a second
You'll use Null Safety (`?`, `?:`, `!!`) constantly in Android development — it's essential for guarding against crashes with nullable view references. Lambda expressions (`{ ... }`) show up everywhere, in button click listeners and list transformations. Data classes (`data class User(val name: String, val age: Int)`) are used to represent your app's data models (user, product, todo item) — Compose UI state is typically shaped using data classes like these.
Let's connect this to a real-world scenario
Writing `var name: String? = null` tells the compiler that 'name' might be null — writing `name?.length` means that if name happens to be null, you get null back instead of a crash. You'll see button clicks written as lambdas over and over, like `Button(onClick = { println("clicked") })`, once we get to Compose in the next lesson.
Let's look at an example together
// Null safety
var name: String? = null
val length = name?.length ?: 0 // 0 if name is null
// Lambda
val greet = { userName: String -> "Hello, $userName!" }
// Data class — will represent our UI state later
data class TodoItem(
val id: String,
val title: String,
val isDone: Boolean = false
)$ println(length)
0
$ println(greet("Aye Aye"))
Hello, Aye Aye!Try it in 5 minutes
Write your own `TodoItem` data class, create 2-3 instances, and inspect the output with `println` (you can use the Kotlin Playground or an Android Studio scratch file).
A quick word of caution
Keep in mind that `!!` is basically forcing the compiler to say 'this thing that could be null definitely isn't' — if it actually turns out to be null, your app will crash immediately.