Android Kotlin Interview Questions

Language fundamentals and best practices.

50 questions in this topic · 8 sample questions below

Practice Kotlin in the quiz engine

Sample questions

  1. You declare val list = mutableListOf(1, 2, 3) and then call list.add(4). What happens?

    • It compiles and runs; the list becomes 1, 2, 3, 4 — correct
    • Compile error because val makes the list immutable
    • Runtime UnsupportedOperationException
    • It compiles but add returns a new list, leaving the original unchanged

    Why: val only makes the reference read-only, not the object it points to; a MutableList can still be mutated. The misconception is that val implies immutability of the contents.

  2. What is the key difference between a read-only List and a truly immutable list in Kotlin?

    • They are identical; List is guaranteed immutable
    • A read-only List lacks mutators but the underlying object may still be a MutableList aliased elsewhere and change — correct
    • A read-only List reference cannot be reassigned, but an immutable one can
    • Read-only lists are backed by arrays; immutable ones by linked structures

    Why: The List interface only omits mutating methods; the actual instance can be a MutableList held by another reference that mutates it, so read-only is not a true immutability guarantee. Kotlin's stdlib does not provide deeply immutable collection types by default.

  3. A Java method returns String with no nullability annotation. In Kotlin you write val s: String = javaCall(). If javaCall returns null at runtime, when does the failure surface?

    • At compile time, since platform types default to non-null
    • Never; s silently becomes an empty string
    • At the assignment site, where an implicit null check throws NullPointerException — correct
    • Only when you later call a method on s

    Why: Platform types let you choose the nullability; assigning to a non-null String inserts an intrinsic null-check that throws right at the assignment. The trap is assuming platform types are checked at compile time.

  4. What does the expression a ?: b evaluate to when a is not null?

    • b, because the Elvis operator always prefers the right operand
    • a, but b is still evaluated for side effects
    • null if a is a nullable type
    • a, and b is not evaluated — correct

    Why: The Elvis operator returns the left operand when it is non-null and only evaluates the right operand otherwise, so b is short-circuited. It does not eagerly evaluate the fallback.

  5. Given val x: String? = null, what does x?.length ?: -1 return?

    • -1 — correct
    • A NullPointerException is thrown
    • 0
    • null

    Why: x?.length short-circuits to null when x is null, and the Elvis operator then supplies -1. It does not throw, because the safe call guards the receiver.

  6. Why does a smart cast fail on an open val or a var declared in another module, even after an explicit null check?

    • Smart casts only work inside functions marked inline
    • The compiler cannot guarantee the value did not change or is not overridden between the check and the use — correct
    • Properties can never be smart-cast, only local variables
    • Smart casts require the property to be lateinit

    Why: Smart casts need a stability guarantee; an open val may be overridden with a custom getter and a mutable or foreign property could change between check and use, so the compiler refuses. Local vals are always smart-castable because they cannot change.

  7. What does the crossinline modifier on a lambda parameter of an inline function enforce?

    • The lambda is not inlined and becomes a real function object
    • The lambda may be stored in a field for later invocation
    • The lambda must be inlined but is forbidden from using non-local returns — correct
    • The lambda is executed on a background thread

    Why: crossinline keeps the lambda inlined yet disallows non-local return-from-enclosing returns, which is needed when the lambda is invoked from a different execution context like another lambda. noinline, by contrast, opts the lambda out of inlining entirely.

  8. Why can you write T::class inside an inline fun with a reified type parameter but not in a normal generic function?

    • Normal generics box their type arguments, reified ones do not
    • Non-inline functions run before type checking
    • reified stores the Class object in a hidden companion field
    • reified copies the actual type into the call site during inlining, defeating erasure at that spot — correct

    Why: Because the inline function body is copied to each call site, a reified parameter can be replaced by the concrete type argument known there, so T::class and is T work. Regular generics are erased at runtime and have no such information.

Practice all 50 Kotlin questions

These 8 are a sample. The full Kotlin bank is scored, tracks your progress, and explains every answer.

Open the quiz

More Android interview topics