Kotlin interview questions and answers for developers

Kotlin interview questions test null safety, the type features that make Kotlin code short (data classes, sealed classes, extension and scope functions) and, above all, coroutines: suspend functions, scopes, structured concurrency, dispatchers, cancellation and Flow. Android and server roles also ask how Kotlin calls and is called from Java. Strong candidates explain what the compiler generates or enforces, not only what the syntax looks like.

By Published 7 min read

Where Kotlin questions come from

Most Kotlin interviews belong to Android teams, followed by JVM backend teams using Spring or Ktor and a growing number of Kotlin Multiplatform projects. The language round usually runs alongside a platform round, so expect a mix: precise language questions, a coroutine exercise, and a review of code that leaks a scope or blocks the main thread. Interviewers who came from Java often probe interop, because real codebases mix both languages for years.

  1. Language screenNullability, data classes, sealed classes, extensions, scope functions. Short definitions plus the trade-off of each.
  2. Coroutines deep diveWhat suspend means, how cancellation travels, why GlobalScope is discouraged, which dispatcher runs what.
  3. Live codingModel a small state machine with sealed types, transform a list with collection operators, or load two resources in parallel with async.
  4. Code reviewSpot a !! that will crash, a swallowed CancellationException, a coroutine launched in the wrong scope, or a Java method that returns null.

Kotlin fundamentals and null safety

Basics asked of freshers and experienced developers
QuestionWhat it testsWhat a strong answer shows
How does Kotlin prevent null pointer exceptions?Null safetyTypes are non-null by default; String? must be checked before use. The compiler forces a safe call, an Elvis fallback, a smart cast after a check, or an explicit !!.
When is !! acceptable?JudgmentRarely: when a null would be a programming error and crashing early is the right signal. In review, each one should have a reason, and most can be replaced with requireNotNull and a message.
What is a platform type?Java interopA type coming from Java with no nullability annotation, shown as String!. The compiler lets you treat it either way, so a null from Java can still crash at runtime.
lateinit versus by lazy?Initializationlateinit is for a non-null var assigned later, such as by dependency injection, and throws if read first. by lazy is for a val computed on first access, synchronized by default.
val, var and const val?Mutabilityval is a read-only reference, var can be reassigned, const val is a compile-time constant of a primitive or String at top level or in an object.
What is the difference between == and ===?Equality== calls equals, so it compares structure; === compares references.
Are Kotlin's List and Map immutable?CollectionsThey are read-only interfaces. The object behind a List may be a MutableList that someone else changes.
What does a smart cast need to work?Type checksThe compiler must prove the value cannot change between the check and the use, which is why it fails on a var property that another thread or a custom getter could change.
Basics asked of freshers and experienced developers. Scroll sideways on a small screen.

Data classes, sealed classes and objects

data class User(val id: Int, val name: String) {
    var lastSeen: Long = 0
}

val a = User(1, "Ada").apply { lastSeen = 100 }
val b = User(1, "Ada")

println(a == b)                  // true: lastSeen is ignored
println(a.copy(name = "Grace"))  // User(id=1, name=Grace)
Only primary-constructor properties take part in equals, hashCode, toString and copy.
sealed interface LoadState {
    object Loading : LoadState
    data class Success(val items: List<String>) : LoadState
    data class Failure(val message: String) : LoadState
}

fun label(state: LoadState): String = when (state) {
    LoadState.Loading -> "Loading"
    is LoadState.Success -> "Showing " + state.items.size + " items"
    is LoadState.Failure -> "Error: " + state.message
}
A sealed hierarchy makes the when expression exhaustive, so no else branch is needed.
  • What does a data class generate? equals, hashCode, toString, copy and componentN functions for destructuring, all from the primary constructor's properties.
  • Why avoid var properties in a data class used as a map key? Changing one changes its hashCode, so the entry becomes unreachable in a HashMap or HashSet.
  • Sealed class or enum? An enum has a fixed set of single instances. A sealed type has a fixed set of subtypes, and each can carry its own data, as Success and Failure do above.
  • What does exhaustiveness buy you? Adding a new subtype breaks every when expression that does not handle it, at compile time, instead of falling into a silent else branch.
  • object versus companion object? An object declaration is a lazily created singleton. A companion object is a singleton tied to a class, used for factory functions and constants that Java sees as static with the right annotations.
  • What is delegation with `by`? Class delegation forwards an interface's methods to another object, giving composition without boilerplate. Property delegation hands get and set to helpers such as lazy, observable or a map.

Extension functions and scope functions

open class Shape
class Circle : Shape()

fun Shape.name() = "shape"
fun Circle.name() = "circle"

fun printName(s: Shape) = println(s.name())

printName(Circle()) // prints "shape"
Extensions are resolved by the static type, not the runtime type.
The five scope functions, which interviewers like to ask you to compare
FunctionObject is referenced asReturnsTypical use
letitLambda resultRun code only when a nullable value is present: user?.let { show(it) }.
runthisLambda resultCompute a value from an object's members in one expression.
withthis (passed as argument)Lambda resultGroup several calls on an object you already have.
applythisThe objectConfigure an object right after creating it.
alsoitThe objectSide effects such as logging without changing the chain.
The five scope functions, which interviewers like to ask you to compare. Scroll sideways on a small screen.
  • Can an extension function access private members? No. It is compiled to a static function that takes the receiver as a parameter, so it sees only what any outside caller sees.
  • What wins when a member and an extension have the same signature? The member, always. Extensions cannot override behavior.
  • What are inline functions and reified type parameters? An inline function's body is copied into the call site, which avoids allocating lambda objects and allows reified type parameters you can check at runtime, such as inline fun <reified T> parse(json: String): T.
  • What are in and out on generics? out makes a type parameter covariant (produced only), in makes it contravariant (consumed only). It is the same idea as Java's wildcards, declared once at the class.

Coroutines and structured concurrency

Coroutine questions decide most Kotlin interviews. The core idea to state clearly: a suspend function can pause without blocking its thread, and every coroutine belongs to a scope whose lifetime bounds it. When the scope is canceled, its children are canceled; when a child fails, the failure travels up.

suspend fun loadDashboard(api: Api): Dashboard = coroutineScope {
    val profile = async { api.profile() }
    val feed = async { api.feed() }
    Dashboard(profile.await(), feed.await())
}

suspend fun readConfig(file: File): String =
    withContext(Dispatchers.IO) { file.readText() }
Two calls in parallel inside one scope. If either fails, the other is canceled and the error reaches the caller.
Coroutine questions by level
QuestionWhat it testsWhat a strong answer shows
What does the suspend keyword do?Compilation modelThe compiler adds a continuation parameter and turns the function into a state machine, so it can return early and resume later on some thread.
launch versus async?Builderslaunch returns a Job for fire-and-forget work; async returns a Deferred with a result you await. An exception in async surfaces at await, but in a regular scope it also cancels the parent.
What is structured concurrency?LifecyclesCoroutines start inside a scope, the scope waits for its children, and cancellation and errors flow through the tree. No coroutine outlives the work that started it.
Why is GlobalScope discouraged?LeaksIts coroutines are tied to nothing, so they keep running after the screen or request that started them is gone. Use viewModelScope, lifecycleScope or a scope your class owns.
Job versus SupervisorJob?Failure handlingUnder a Job, one failing child cancels its siblings and the parent. Under a SupervisorJob, children fail independently, which suits independent UI tasks.
Which dispatcher for what?ThreadsMain for UI updates, IO for blocking I/O such as files and JDBC, Default for CPU work. withContext switches for a block and returns to the caller's dispatcher.
How does cancellation work?CooperationCancellation sets a flag; suspending library calls check it and throw CancellationException. A tight CPU loop must call ensureActive or yield to notice.
Why is catching Exception around suspend calls risky?Cancellation bugsIt also catches CancellationException and can keep a canceled coroutine running. Rethrow it, or catch only the exceptions you expect.
Coroutine questions by level. Scroll sideways on a small screen.

Flow, StateFlow and SharedFlow

  • What is a cold flow? Its code runs each time someone collects it, from the start, like calling a function. Nothing runs without a collector.
  • StateFlow versus SharedFlow? StateFlow always has a current value, replays it to new collectors and skips equal consecutive values: a fit for UI state. SharedFlow is configurable for replay and buffering: a fit for events.
  • What does flowOn change? The dispatcher of the operators upstream of it. Collection still happens in the collector's context.
  • How would you build search-as-you-type? Debounce the query flow, drop repeats with distinctUntilChanged, and use flatMapLatest so a new query cancels the old search.
  • How do you collect a flow safely on Android? In a lifecycle-aware way, such as repeatOnLifecycle with the STARTED state, so collection stops when the screen is not visible.
  • Channel or Flow? A channel is a hot pipe between coroutines where each value goes to exactly one receiver. A flow is a description of a stream. Most app code exposes flows.

Java interop questions

Interop for teams that mix Kotlin and Java
QuestionWhat it testsWhat a strong answer shows
How does Java call a companion object function as static?@JvmStaticAnnotate it with @JvmStatic; otherwise Java calls it through the Companion instance.
How do default arguments look from Java?@JvmOverloadsJava sees one method with every parameter unless you add @JvmOverloads, which generates the shorter overloads.
Kotlin has no checked exceptions. What does Java see?@ThrowsNothing is declared, so Java callers cannot catch the checked exception cleanly. Add @Throws to declare it.
How do you make Java code null-safe for Kotlin callers?AnnotationsAdd nullability annotations such as @Nullable and @NonNull, so Kotlin sees real types instead of platform types.
How do Kotlin lambdas work with Java interfaces?SAM conversionA Java interface with one abstract method accepts a Kotlin lambda directly. For Kotlin interfaces you declare a fun interface.
Interop for teams that mix Kotlin and Java. Scroll sideways on a small screen.

Fictional example

Answering "Tell me about a coroutine bug you fixed"
In a shopping app, the cart screen sometimes showed a stale total after the user left and came back. The repository launched its refresh in a scope created with a plain Job and never canceled, so old refreshes kept running and wrote results after newer ones. I moved the work into viewModelScope, exposed the total as a StateFlow, and used flatMapLatest on the cart ID so each new request canceled the previous one. I also found a try-catch around the network call that caught Exception and swallowed cancellation; I narrowed it to IOException. The stale totals stopped, and a test with a TestDispatcher now checks that leaving the screen cancels the refresh.

Two-week Kotlin preparation plan

  • Days 1 to 3: null safety, data classes, sealed types and when. Rewrite a small Java model in Kotlin and explain each change.
  • Days 4 and 5: extensions, scope functions, inline and reified, generics variance. Write one example per scope function where it reads best.
  • Days 6 to 9: coroutines. Build parallel loading with async, a cancellation test, and one example each of Job versus SupervisorJob failures.
  • Days 10 and 11: Flow, StateFlow and SharedFlow, including a search-as-you-type pipeline.
  • Days 12 to 14: interop annotations, then a timed mock: a feature with a ViewModel or a Ktor endpoint, with tests using runTest.

The closest language in this set is Swift, which shares null safety and value-focused design: see Swift interview questions. For another managed language with nullable references and async/await, compare C# interview questions. Role-level loops are covered in software engineer interview questions.

Natively, an AI interview assistant for Mac and Windows, transcribes your mock Kotlin interviews, so you can check afterward whether your structured concurrency answer actually mentioned the scope. When you practice, it can read a Kotlin task from a screenshot, give a nudge or an outline of a solution, and with Pro or the free trial draw on the résumé and job description you add. Each session's transcript and notes are saved for review.

Questions people ask

What Kotlin questions are asked in interviews?

Null safety and platform types, data and sealed classes, extension and scope functions, inline and reified, and coroutines: suspend, launch versus async, structured concurrency, dispatchers, cancellation and Flow.

How do I explain Kotlin coroutines in an interview?

Say that a suspend function pauses without blocking its thread, that every coroutine belongs to a scope that bounds its lifetime, and that cancellation and failures travel through that tree. Then give one example with coroutineScope and async.

What Kotlin topics matter for Android developer interviews?

viewModelScope and lifecycle-aware collection, StateFlow for UI state, dispatchers for I/O and main-thread work, sealed classes for screen state, and testing coroutines with runTest.

Do Kotlin interviews ask about Java?

Often, because most codebases mix both. Expect platform types, @JvmStatic, @JvmOverloads, @Throws and SAM conversion.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP