Android

Kotlin Language Essentials for Android

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

24 면접 질문·
Junior
1

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

답변

'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?

답변

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?

답변

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 면접 질문

다음 면접을 위해 Android을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기