Android

Kotlin Language Essentials for Android

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

24 domande da colloquioยท
Junior
1

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

Risposta

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

Risposta

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?

Risposta

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 domande da colloquio

Padroneggia Android per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis