Android

Kotlin Language Essentials for Android

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

24 perguntas de entrevistaยท
Junior
1

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

Resposta

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

Resposta

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?

Resposta

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 perguntas de entrevista

Domine Android para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis