tezvyn:

Purpose of Kotlin's safe call (`?.`) and Elvis (`?:`) operators?

Source: kotlinlang.orgbeginner

This tests your grasp of Kotlin's null safety philosophy. A good answer defines the safe call (`?.`) for conditional access and the Elvis operator (`?:`) for default values, then combines them. A red flag is using verbose `if/else` checks for simple cases.

This question tests your grasp of Kotlin's core philosophy for preventing `NullPointerException`s at compile time. A strong answer first defines the safe call (`?.`) for conditional chaining and the Elvis operator (`?:`) for providing a default value. Then, it combines them in a concise example like `user?.name?.length ?: 0`. The biggest red flag is suggesting the non-null assertion operator (`!!`), which defeats the purpose of null safety.

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.

Purpose of Kotlin's safe call (`?.`) and Elvis (`?:`) operators? · Tezvyn