Android

Kotlin Language Essentials for Android

var vs val, null safety, data classes, when expressions, extension functions, scope functions and fundamental Kotlin concepts

24 câu hỏi phỏng vấn·
Junior
1

What is the difference between 'var' and 'val' in Kotlin?

Câu trả lời

'var' declares a mutable (modifiable) variable, while 'val' declares an immutable (read-only) variable. It's recommended to use 'val' by default to promote immutability and avoid bugs.

2

What does the '?' operator after a type mean in Kotlin?

Câu trả lời

The '?' operator indicates that the variable can contain null. For example, 'String?' means the variable can be a String or null. This is the basis of Kotlin's null safety system.

3

What does the '!!' operator do in Kotlin?

Câu trả lời

The '!!' operator (not-null assertion) forces the compiler to treat a nullable value as non-null. If the value is null, a NullPointerException is thrown. Only use when you're certain the value is not null.

4

What is the Elvis operator '?:' used for in Kotlin?

5

What is a data class in Kotlin?

+21 câu hỏi phỏng vấn

Nắm vững Android cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí