Kotlin Interview Questions and Answers
Null safety, coroutines, extension functions and Java interop.
Whether you are preparing for entry-level Kotlin interview questions for freshers or senior software engineer interview questions addressing concurrency, scalability, and system architecture, this track provides peer-reviewed model answers with syntax walkthroughs, edge cases, and practical interview tips.
1 How does Kotlin handle null safety? Easy
Kotlin's type system distinguishes nullable from non-nullable types. String cannot hold null; String? can. This moves null checks to compile time and largely eliminates NullPointerException.
var a: String = "hi"
var b: String? = null
// a.length // compile error on b.length
println(b?.length) // safe call, prints null
println(b?.length ?: 0) // Elvis operator, default value
b?.let { println(it) } // runs only when non-null
val c = b!!.length // asserts non-null, throws if null
Tools include the safe call ?., the Elvis operator ?:, let/also, and the not-null assertion !!, which should be avoided because it reintroduces crashes. lateinit var is for non-null properties initialised after construction, and by lazy for deferred initialisation. Values coming from Java have platform types with unknown nullability, so guard or annotate them at the boundary.
2 What is the difference between val and var? Easy
val declares a read-only reference that cannot be reassigned after initialisation. var declares a mutable reference that can be reassigned.
val name = "Ada" // cannot reassign
var count = 0
count += 1 // ok
val list = mutableListOf(1)
list.add(2) // ok: the reference is fixed, contents are mutable
The restriction applies to the reference, not the object's internal state, which is why mutating a mutableList held by a val is legal. Prefer val by default: it makes code easier to reason about, is friendlier under concurrency and helps the compiler. Use var only when reassignment is genuinely needed. A val property can still have a custom getter that computes a fresh value on each access. For truly immutable objects, also make the underlying data immutable, since val alone does not prevent mutation through other references.
Frequently Asked Questions About Kotlin Interviews
What do hiring managers evaluate in Kotlin technical rounds?
Technical interviewers look for foundational fluency, idiomatic syntax, clarity when communicating complex logic, and awareness of performance trade-offs (e.g. memory footprint, render performance, and network latency) in production environments.
What are the best interview tips for practicing Kotlin questions?
Use active recall: summarize each answer in your own words before revealing the model solution. Focus on explaining why a certain approach is chosen rather than just memorizing code syntax.