Explain val vs. var and null safety in Kotlin

Tests your grasp of Kotlin's core principles: immutability and compile-time null safety. Define `val` (read-only) vs. `var` (mutable), declare nullables with `?`, and identify the risk as runtime `NullPointerException`s.
This tests your understanding of Kotlin's design choices for variables and its compile-time approach to preventing null errors. A great answer defines `val` (read-only reference) vs. `var` (mutable), then shows how to declare a nullable type with `?`. The main risk is a `NullPointerException` at runtime, which Kotlin mitigates via compile-time checks like safe calls (`?.`). A red flag is saying `val` makes the object itself immutable.
Read the original → kotlinlang.org
- #kotlin
- #android
- #null safety
- #immutability
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.