tezvyn:

Explain val vs var in Kotlin and null safety risks

Source: kotlinlang.orgbeginner

WHAT IT TESTS: Kotlin mutability and compile-time null safety. ANSWER OUTLINE: val is read-only, var is mutable; nullables use ? like String?; risk is NullPointerException if checks are missed. RED FLAG: Calling val deep immutability or defaulting to !!.

WHAT IT TESTS: Your understanding of Kotlin reference immutability versus mutability and compile-time null safety as a type-system feature. ANSWER OUTLINE: A strong answer states that val is a read-only reference while var is reassignable; nullables are declared with ? such as String?; the risk is that nullability propagates and every access must be checked to avoid NullPointerException. RED FLAG: Confusing val with object immutability, claiming Kotlin has zero NPEs, or using !! as a default fix.

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 in Kotlin and null safety risks · Tezvyn