Kotlin Val/Var & Null Safety
Lesson Overview: Eliminate NullPointerExceptions with nullable types (?) and val immutability.
Safe & Expressive JVM Language
Prefer val (read-only) over var (mutable). Nullable types like String? require safe calls (?.) or Elvis defaults (?:).
- fun main() { println("Hello") }
- when replaces verbose switch chains cleanly
Test Yourself With Exercises
Declare an immutable read-only variable in Kotlin:
pi = 3.14159