Safe Calls and Elvis
?. and ?: operators.
Beyond if Checks
Checking every nullable value with an if works, but it gets verbose fast. Kotlin offers compact operators built for null handling.
This lesson covers the safe call operator ?. and the Elvis operator ?:, two tools you will use constantly.
The Safe Call Operator
The ?. operator calls a method only if the value is not null. If it is null, the whole expression evaluates to null instead of crashing.
It is a safe shortcut for the if-not-null pattern.
fun main() {
val name: String? = "Coddy"
println(name?.length)
}