Skip to content
tezvyn:

Kotlin

225 bites tagged Kotlin — interview questions with model answers, and 60-second explainers.

Android & Kotlin2 min read

Model a Room one-to-many Playlist-to-Song relationship

Tests Room relational modeling. Strong answer: Song foreign key, `@Embedded` Playlist with `@Relation` to `List<Song>`, DAO wrapped in `@Transaction`. Red flag: embedding songs in Playlist or skipping `@Transaction`, which causes N+1 queries.

Android & Kotlin2 min read

How do you add a non-null column with a default in Room?

Bump version; run ALTER TABLE ADD COLUMN with NOT NULL DEFAULT in a Migration; register via addMigrations. SQLite ALTER TABLE semantics and Room Migration wiring. Dropping tables or omitting DEFAULT on existing rows.

Android & Kotlin2 min read

How do you define a Room table for a Kotlin data class?

Tests your grasp of the minimum Room entity contract. A strong answer cites Entity and PrimaryKey, notes Kotlin defaults work out of the box, and mentions ColumnInfo for renaming.

Android & Kotlin2 min read

Why choose DataStore over SharedPreferences for a toggle?

This tests your grasp of modern Android storage safety beyond syntax. A strong answer names DataStore's async coroutines API, type safety, transactions, and migration support. A red flag is claiming SharedPreferences is simpler while ignoring ANR risk.

Android & Kotlin2 min read

Difference between remember and rememberSaveable

Remember survives recompositions only; rememberSaveable uses Bundle state for config changes and process death; use for UI state after recreation. Compose state vs saved state. Claiming it uses ViewModel or disk.

Android & Kotlin2 min read

What is remember in Compose and how do you use mutableStateOf?

This tests state survival across recompositions. Good answers say remember caches values across recompositions, pairs with mutableStateOf for observable state, and shows a counter. A red flag is mutableStateOf without remember, state resets per recomposition.

Android & Kotlin2 min read

How would you implement a type-safe Kotlin DSL for a UI Form?

Tests Kotlin DSL scoping with lambda receivers and extensions. Strong answers sketch a Form builder using initTag, explain T.() -> Unit implicit this for child elements, and add DslMarker to block scope leaks. Red flag: describing it as simple method chaining.

Android & Kotlin2 min read

What is a reified type parameter in Kotlin?

Tests JVM type erasure and inline function mechanics. Strong answer: reified preserves generic types at runtime via inline expansion, enabling is T checks without Class<T> passing. Red flag: claiming reified works without inline or outside functions.

Android & Kotlin2 min read

Describe coroutine cancellation mechanics and cooperative suspend functions

Tests cooperative cancellation mechanics. cancel() sets a Job to cancelling; suspend functions check this at suspension points and throw CancellationException, yet a tight non-suspending loop never checks and keeps running.

Android & Kotlin2 min read

How do buffer, conflate, and collectLatest manage Kotlin Flow backpressure?

Backpressure is fast emit vs slow collect; buffer() suspends the producer when full, conflate() drops stale values, and collectLatest() cancels active collection to… Coroutine flow control and suspension-vs-dropping tradeoffs.

Android & Kotlin2 min read

Explain Kotlin's declaration-site variance with in and out

Out T means covariant producer (read), in T means contravariant consumer (write), removing wildcard noise. Understanding declaration-site variance versus wildcards. Confusing in/out with bounds or claiming immutability.

Android & Kotlin2 min read

What is a CoroutineDispatcher and when to use Default versus IO?

This tests thread pool selection and the CPU versus IO distinction. A strong answer maps CoroutineDispatcher to the thread pool, Default to CPU work, IO to blocking IO, and Main to the UI thread.

Android & Kotlin2 min read

Hot vs cold Kotlin Flows and StateFlow use case

Tests grasp of flow lifecycle and collector behavior. A strong answer contrasts cold Flows, which restart per collector, with hot StateFlows broadcasting to all observers. Red flag: using Flow for UI state without citing config changes or initial value.

Android & Kotlin2 min read

How does Structured Concurrency handle cancellations and exceptions?

This tests scope-bound lifecycle management preventing leaks. Cover scope cancellation cascading to children, exceptions propagating up to cancel siblings, and launch or async requiring a scope. A red flag is treating coroutines as fire-and-forget threads.

Android & Kotlin2 min read

What is a suspend function in Kotlin and its compiler rules?

This tests your understanding of suspendable computations and compiler transformation. A strong answer notes non-blocking suspension, the call-from-suspend-context rule, and compiler support for pausing and resuming. A red flag is claiming they block threads.

Android & Kotlin2 min read

Explain the difference between launch and async in Kotlin Coroutines

This tests scope behavior and side effects versus results. A strong answer says launch returns a Job for side effects, async returns a Deferred for results, and both are scope children. A red flag is using async for all tasks or ignoring exception handling.

Android & Kotlin2 min read

What does inline solve for higher-order functions, and what is reified?

It tests lambda overhead and type erasure. Answer: inline flattens lambdas into call sites to remove allocation and virtual calls; reified needs inline so the compiler knows the concrete type at the call site, enabling is T checks.

Android & Kotlin2 min read

Compare Kotlin apply and let scope functions

Apply uses this and returns receiver for configuration; let uses it and returns lambda result for null-safe transforms. Your grasp of Kotlin scope mechanics. Calling them interchangeable or ignoring return values.

Android & Kotlin2 min read

When would you use a sealed class instead of an enum?

This tests closed hierarchies versus singleton constants. A strong answer contrasts enums with sealed class instances, shows a NetworkResult example with data-bearing branches, and highlights exhaustiveness.

Android & Kotlin2 min read

Explain higher-order functions and implement filterAndTransform

Tests whether you can define higher-order functions and use lambdas idiomatically in Kotlin. A strong answer defines HOFs as functions that take or return functions, then implements filterAndTransform with filter and map.

Android & Kotlin2 min read

Explain lateinit var versus val by lazy in Android

Tests deferred initialization and lifecycle coupling. Great answers contrast lateinit var's imperative assignment with lazy's first-access delegation, mapping lateinit to injected Activity fields and lazy to expensive computed objects.

Android & Kotlin2 min read

What are the primary advantages of using a data class?

Tests Kotlin boilerplate reduction and value semantics. Name three generated functions like equals, hashCode, and copy; explain structural equality; and show copy updating immutable UI state.

Android & Kotlin2 min read

What is an extension function? Write a hasWhitespace extension for String.

Explain receiverType.functionName adds behavior without inheritance; write hasWhitespace with any { it.isWhitespace() }. Kotlin extensions are static dispatch, not true members. Extensions modify classes or override.

Android & Kotlin2 min read

Explain val vs var in Kotlin and null safety risks

Val is read-only, var is mutable; nullables use ? like String?; risk is NullPointerException if checks are missed. Kotlin mutability and compile-time null safety. Calling val deep immutability or defaulting to !!.

Get Kotlin bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.