Kotlin
225 bites tagged Kotlin — interview questions with model answers, and 60-second explainers.
Creating a native module with a sync method
Extend the RN base class, mark the method exported and synchronous, register in a package or bridging file. native module mechanics across platforms.
Kotlin 2.4.0 Ships Stable Context Parameters and UUID API
Kotlin 2.4.0 ships stable context parameters, a built-in UUID API, and Java 26 support. Context parameters replace manual dependency threading through call chains.
Kotlin 2.4.0 Preview, Unified Toolchain, and LSP Alpha Land
Kotlin 2.4.0 stabilizes context parameters and explicit backing fields. A new Kotlin Toolchain unifies build, test, and agent workflows under one command, while the Language Server hits Alpha.
Koog 1.0 Stabilizes Kotlin AI Agent Framework
Koog 1.0 locks APIs for one year in JetBrains' Kotlin AI agent framework, adding local Android LiteRT inference and OpenTelemetry. JVM teams can build production agents without breaking changes. Adopt stable core first, then add beta features as needed.
Kotlin 2.4.0 ships Swift package support and Java 26
Kotlin 2.4.0 adds Swift package dependencies for Native, Java 26 for JVM, and WebAssembly Component Model. Multiplatform teams can consume Swift libraries directly and target newer Java. Upgrade via IntelliJ IDEA, Android Studio, or Gradle.
Architect periodic and on-demand sync with WorkManager
Tests combining periodic and push WorkManager requests safely. Outline: one Worker class, PeriodicWorkRequest hourly and OneTimeWorkRequest on push, with ExistingWorkPolicy.KEEP plus constraints. Red flag: two Workers, no deduplication, or ForegroundService.
How would you implement a constrained photo upload with WorkManager?
Tests knowledge of WorkManager constraints and retry policies for deferrable background uploads. A strong answer names OneTimeWorkRequest with Constraints for charging and unmetered network, plus BackoffPolicy for retry.
Chain WorkManager tasks and pass a file URI between workers.
This tests WorkManager chaining and data passing. A strong answer chains Download, Unzip, and Process with WorkContinuation, passes URI via outputData, and reads it with inputData. A red flag is suggesting global state, SharedPreferences, or thread blocking.
Functional difference between @Binds and @Provides in Hilt
Tests if you understand Hilt code generation tradeoffs. @Binds wires an existing injectable implementation to an interface with less overhead; @Provides constructs instances manually.
Explain Retrofit Interceptors and write a static API key interceptor
Tests OkHttp interception and application versus network scope. Strong answers build a new request adding X-Api-Key via newBuilder and chain.proceed; contrast addInterceptor once versus addNetworkInterceptor per hop.
How would you use Retrofit to GET /posts/{id} and key components?
This checks your understanding of Retrofit's three-layer setup. You need a data class for JSON parsing, an interface with @GET and @Path, and a Retrofit.Builder with baseUrl and a converter.
Explain the difference between Kotlin's let, run, with, apply, and also
Group by this (apply, run, with) vs it (let, also), then by return type. Whether you know the two axes of Kotlin scope functions: receiver (this vs it) and return value (context vs lambda result). Using them randomly.
What do the safe call and Elvis operators do in Kotlin?
?. yields null if receiver is null; ?: provides the right operand when left is null; chain as val len = str?.length ?: 0. Kotlin null-safety and default-value fallback. Using !!, verbose if checks, or stating ?.
What is the role of TestDispatcher and runTest in coroutine testing?
This tests coroutine test infrastructure and virtual time control. A great answer says runTest installs a TestDispatcher and TestScope, skips delays automatically, and exposes advanceTimeBy to test timeouts instantly.
How do you test a Compose click and verify state change?
This tests Compose semantics and interaction-to-assertion flow. Mention ComposeTestRule, onNodeWithTag, performClick, and assert on the changed node with assertIsDisplayed or assertTextEquals.
Unit test a ViewModel exposing StateFlow in a local JVM test
Tests coroutine hygiene and flow collection strategy. A strong answer covers injecting a TestDispatcher, using runTest, collecting emissions in a background scope, and asserting states.
Explain Structured Concurrency in Kotlin Coroutines
Structured concurrency binds coroutines to a scope; parent cancellation propagates to all children, preventing leaks. your grasp of Kotlin coroutine parent-child scope hierarchies. calling them unmanaged threads.
What is the difference between viewModelScope and lifecycleScope?
This tests scope ownership across configuration changes. viewModelScope survives rotation because it lives in ViewModel, while lifecycleScope dies with UI; use former for logic and latter for UI tasks. Never launch data loads in lifecycleScope.
How do you make a network request in an Activity using coroutines?
This tests main thread safety and coroutine dispatchers. A strong answer cites NetworkOnMainThreadException, uses lifecycleScope, and switches to Dispatchers.IO. Red flag: suggesting Dispatchers.Main for the network call or omitting the exception entirely.
How do you inject UserRepository into a ViewModel with Hilt?
Tests Hilt constructor injection for classes you own. Annotate UserRepository's constructor with @Inject so Hilt auto-provides it to consumers like a @HiltViewModel. Red flag: using a @Provides module for a class you control.
Parse polymorphic media JSON with Kotlin sealed classes and custom serializers
Sealed Media with Image and Video; use Moshi Factory or kotlinx.serialization keyed on the type field. Polymorphic deserialization with Kotlin sealed classes. Manual JSONObject branching or reflection-based parsing.
How do you upload a file with text data in Retrofit?
Tests multipart uploads versus JSON bodies. Strong answer: @Multipart, @POST, @Part; file as MultipartBody.Part and text as RequestBody; avoid @Field. Red flag: suggesting @Body with a data class.
How do you differentiate network and server errors in suspend functions?
Catch IOException for connectivity and HttpException for HTTP errors; wrap in a sealed Result. Structured error handling in coroutines and mapping exceptions to recovery. Catching Exception or exposing raw errors to UI.
How do you configure Moshi or Kotlinx.serialization for JSON key mismatches?
This tests library-specific field-mapping annotations. For Kotlinx.serialization use @SerialName with the JSON key; for Moshi use @Json with the name parameter. A red flag is confusing the two or using manual mapping instead of the built-in decorator.
Get Kotlin bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.