Explain val, var, and null safety in Kotlin

This tests your grasp of immutability and Kotlin's compile-time null safety. Define `val` (immutable reference) vs. `var` (mutable), explain nullable types using `?`, and state the risk is `NullPointerException`. A red flag is confusing `val` with a constant.
This tests your grasp of Kotlin's core principles: preferring immutability (`val`) and enforcing compile-time null safety to prevent runtime NPEs. A great answer defines `val` as an immutable reference and `var` as mutable, then explains that nullability is an explicit opt-in via the `?` suffix (e.g., `String?`). The primary risk is a `NullPointerException` if a nullable type is dereferenced without a check. A common mistake is confusing `val` with `const`.
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.