Kotlin language interview questions
Null safety, classes, equality, scope functions, generics, inline functions and what Kotlin 2 and the K2 compiler changed.
– interview-ready · 20 questions in this topic
– of 20 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- How Kotlin code runs on AndroidOrder the steps
- Null safety and !!Predict
- val, var and const valPredict
- Data classesPredict
- Sealed classes and exhaustive whenPredict
- == vs ===Predict
- let, run, with, apply, alsoPredict
- Extension functionsPredict
- lateinit vs by lazyPredict
- inline functions and reifiedPick the fix
- Lambdas, function types and fun interfacesPredict
- object, companion object and singletonsPick the fix
- Generics: in, out and star projectionPredict
- Delegation with byPredict
- Smart casts and their limitsPredict
- Value classesPredict
- Collections vs sequencesPredict
- Kotlin 2 and the K2 compilerPick the fix
- @JvmStatic, @JvmField and @JvmOverloadsPick the fix
- Visibility: internal and friendsPick the fix
Practise this topic
Flashcards · 26
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 20 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 4 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
Elvis operator
a ?: b returns a if it isn't null, otherwise b; b can be throw or return.
Kotlin typealias
A typealias gives a type another name; it doesn't create a new type.
data object
data object gives a singleton a readable toString, plus equals and hashCode.
Trailing lambdas
If a function's last parameter is a function, the lambda can go outside the parentheses.
when guard conditions
Kotlin 2.2 made guard conditions in when stable: is Shape.Circle if radius > 0 ->.
Kotlin 2.2+
Range operators
1..5 includes 5; 1..<5 (rangeUntil) excludes it.
Printable cheat sheet · Review your weak spots in this topic
Share your progress
Sources: Question outline adapted from Android-Interview-Questions by Mohsen Mirhoseini, licensed under Apache 2.0. We reorganised the questions, rewrote every answer and added new ones. Credits and license