tezvyn:

Explain val vs. var and null safety in Kotlin

Source: kotlinlang.orgbeginner

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

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.

Explain val vs. var and null safety in Kotlin · Tezvyn