How to Pass a Kotlin Interview: Top Advanced-Level Questions

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

How to Pass a Kotlin Interview: Top Advanced-Level Questions



An interview for a Senior Kotlin developer position is not just a syntax check. Interviewers want to see a deep understanding of the language architecture, compilation specifics, and multithreading. In this article, we will break down the most complex and frequently asked questions that will help you confidently pass a technical interview. The material is aimed at developers who already have experience with Kotlin and Java.



1. Coroutines: Structured Concurrency and Task Cancellation



Coroutines are one of Kotlin's strongest features. An advanced question often concerns Structured Concurrency. The interviewer might ask: "What happens if a child coroutine throws an exception, and the parent coroutine does not catch it?"



The answer lies in the Job hierarchy. If a child coroutine (launched via coroutineScope or inside launch) fails with an exception, it propagates to the parent. The parent coroutine is cancelled, and all its child tasks are cancelled as well. This makes the code predictable and safe.



An example worth showing in an interview:



import kotlinx.coroutines.*

fun main() = runBlocking { try { coroutineScope { launch { delay(100) throw RuntimeException("Error in child coroutine") } launch { delay(200) println("This coroutine will not execute if the first one fails") } } } catch (e: Exception) { println("Exception caught: ${e.message}") } println("Program continues execution")}


Another common question is coroutine cancellation. How to properly cancel a coroutine? Use Job.cancel() and check the state via ensureActive() or isActive inside long-running operations.



2. Inline Functions and Reified Types



Advanced developers should understand why inline functions are needed. The question might be: "Why does Kotlin not allow using reified types without inline?"



Answer: reified types only work inside inline functions because the code of such a function is inlined directly at the call site. The compiler substitutes the specific type at compile time, which is impossible for regular generic functions due to type erasure on the JVM.



An example demonstrating the power of reified:



inline fun <reified T> isInstance(value: Any): Boolean {    return value is T}

fun main() { println(isInstance<String>("Hello")) // true println(isInstance<Int>("Hello")) // false}


You will also be asked about noinline and crossinline. noinline prevents inlining of a specific lambda parameter, while crossinline prohibits using return inside the lambda (non-local return).



3. Delegates: Delegates.observable, vetoable, and Custom Delegates



A question about delegates is a classic. The advanced level implies not only knowledge of built-in delegates (lazy, observable) but also the ability to write your own.



Example: "How to implement a delegate that logs every property change?"



import kotlin.properties.ReadWritePropertyimport kotlin.reflect.KProperty

class LoggingDelegate<T>(private val initialValue: T) : ReadWriteProperty<Any?, T> { private var value = initialValue

override fun getValue(thisRef: Any?, property: KProperty<*>): T { println("Reading ${property.name}: $value") return value }

override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { println("Writing ${property.name}: $value") this.value = value }}

class User { var

Blogs

Book Recommendations