🎯

Kotlin MCQ

Test your Kotlin knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.

100 Questions 41 Beginner 40 Intermediate 19 Advanced

How This Practice Test Works

Every question below expands right on this page — click a question to reveal its four options, pick the one you think is correct, and you'll get instant feedback along with the correct answer and a short explanation of the reasoning. Questions are grouped by difficulty, so start with the 41 beginner questions to confirm your fundamentals, work through the 40 intermediate ones, and finish with the 19 advanced questions that mirror what exams and technical screenings actually ask. There's no sign-up, no timer, and no limit — retake the test as often as you like.

Curated by Tech Baithak Editorial Team  ·  Last updated: June 2026

1

Which company developed the Kotlin programming language?

B

Correct Answer

JetBrains

Explanation

Kotlin was developed by JetBrains and first released in 2011. It became an official language for Android development in 2017.

2

How do you declare an immutable variable in Kotlin?

C

Correct Answer

val x = 5

Explanation

val declares a read-only (immutable) reference. var declares a mutable variable that can be reassigned.

3

What is the Kotlin keyword for declaring a nullable type?

B

Correct Answer

?

Explanation

Appending ? to a type (e.g., String?) marks it as nullable, allowing null values. Without ?, Kotlin types are non-nullable by default.

4

What does the Elvis operator ?: do?

C

Correct Answer

Returns the left-hand value if non-null, otherwise the right-hand value

Explanation

The Elvis operator (val result = a ?: b) returns a if it's not null, otherwise returns b.

5

What is a data class in Kotlin?

B

Correct Answer

A class that auto-generates equals, hashCode, toString, copy, and componentN functions based on primary constructor properties

Explanation

Data classes (data class Person(val name: String)) are designed to hold data and auto-generate boilerplate methods.

6

How do you define a function in Kotlin?

C

Correct Answer

fun greet(): Unit

Explanation

Kotlin uses the fun keyword to declare functions.

7

What is a Kotlin object declaration?

B

Correct Answer

A thread-safe singleton

Explanation

object MyObject { } declares a singleton in Kotlin — only one instance exists, created lazily on first access.

8

What does the safe call operator ?. do?

B

Correct Answer

Calls a method only if the receiver is not null; otherwise returns null

Explanation

str?.length returns null if str is null rather than throwing a NullPointerException.

9

What is a companion object in Kotlin?

B

Correct Answer

An object declared inside a class that provides class-level (static-like) members

Explanation

companion object acts like static members in Java, accessible via the class name, e.g., MyClass.create().

10

What is a sealed class in Kotlin?

B

Correct Answer

A class that restricts its subclasses to be defined in the same file

Explanation

Sealed classes restrict the class hierarchy to a known set of subclasses, enabling exhaustive when expressions.

11

How do you declare a primary constructor in Kotlin?

B

Correct Answer

class Person(val name: String)

Explanation

Kotlin allows declaring the primary constructor directly in the class header with optional val/var to create properties.

12

What is string interpolation in Kotlin?

B

Correct Answer

Embedding expressions inside a string using $ or ${}

Explanation

"Hello, $name!" or "${user.fullName}" embeds variable values or expressions directly in string literals.

13

What is the difference between == and === in Kotlin?

B

Correct Answer

== checks structural equality (calls equals()); === checks referential equality

Explanation

In Kotlin, == is the safe structural equality (null-safe equals()), while === checks if two references point to the same object.

14

Which keyword is used for type casting in Kotlin?

B

Correct Answer

variable as Type

Explanation

Kotlin uses as for unsafe casting and as? for safe casting (returns null instead of throwing on failure).

15

What is a lambda expression in Kotlin?

B

Correct Answer

An anonymous function that can be stored in a variable or passed as an argument, written as { params -> body }

Explanation

Kotlin lambdas are written as { x: Int -> x * 2 }. If there's a single parameter, you can use the implicit it.

16

What does the when expression replace in Kotlin?

C

Correct Answer

The switch statement from Java

Explanation

when replaces Java's switch and is more powerful — it can match ranges, types, and expressions, and can be used as a statement or expression.

17

What is the Unit type in Kotlin?

A

Correct Answer

An alias for void in Kotlin

Explanation

Unit corresponds to Java's void. Functions that return nothing return Unit, which can be omitted from the function signature.

18

How do you declare an interface in Kotlin?

B

Correct Answer

interface MyInterface

Explanation

Kotlin uses the interface keyword. Unlike Java, Kotlin interfaces can have property declarations and default implementations.

19

What is an extension function in Kotlin?

B

Correct Answer

A function that adds new functionality to an existing class without modifying its source code

Explanation

fun String.shout() = uppercase() + "!" adds a shout() method to String without subclassing or modifying String.

20

What does the !! (not-null assertion) operator do?

A

Correct Answer

Converts a nullable type to non-null, throwing KotlinNullPointerException if null

Explanation

value!! asserts the value is non-null. If it is null, a KotlinNullPointerException is thrown. Use sparingly.

21

What is the Kotlin equivalent of Java's static methods?

D

Correct Answer

Both B and C are valid

Explanation

Kotlin doesn't have static. You can use companion object functions (class-level) or top-level functions (package-level) as alternatives.

22

What is the difference between List and MutableList in Kotlin?

B

Correct Answer

List is read-only; MutableList supports add, remove, and set operations

Explanation

Kotlin distinguishes read-only (List) from mutable (MutableList) collection interfaces, promoting immutability by default.

23

What does the init block do in a Kotlin class?

B

Correct Answer

Contains code that runs as part of the primary constructor

Explanation

init blocks run in declaration order as part of primary constructor execution, useful for validation or complex initialization.

24

How do you declare default parameter values in Kotlin?

A

Correct Answer

fun greet(name: String = "World")

Explanation

Kotlin supports default parameter values directly in the function signature, reducing the need for overloads.

25

What is a Kotlin enum class?

B

Correct Answer

A class with a fixed set of named constant instances

Explanation

enum class Direction { NORTH, SOUTH, EAST, WEST } creates named constants. Enum classes can have properties and methods.

26

What is the purpose of the open keyword in Kotlin?

B

Correct Answer

To mark a class or method as inheritable/overridable (since all are final by default)

Explanation

In Kotlin, classes and members are final by default. The open modifier allows them to be subclassed or overridden.

27

What does the let scope function do?

B

Correct Answer

Executes a lambda on a non-null object and returns the lambda's result; object is referred to as it

Explanation

let is often used for null-safe chaining: nullableObj?.let { doSomethingWith(it) }. It returns the lambda result.

28

What does the apply scope function return?

C

Correct Answer

The receiver object itself

Explanation

apply executes a lambda where this refers to the receiver and returns the receiver itself, ideal for object initialization.

29

What is a higher-order function?

B

Correct Answer

A function that takes other functions as parameters or returns a function

Explanation

Higher-order functions treat functions as first-class citizens. Examples include map, filter, and reduce from the standard library.

30

Which collection function transforms each element to a new value?

C

Correct Answer

map

Explanation

map applies a transformation lambda to each element and returns a new list of results.

31

How does Kotlin handle null safety compared to Java?

B

Correct Answer

Kotlin types are non-nullable by default; null must be explicitly opted into with ?

Explanation

Kotlin's type system distinguishes nullable (String?) from non-nullable (String) at compile time, catching most NullPointerExceptions before runtime.

32

What is a property in Kotlin?

B

Correct Answer

A class field with optional custom getter and setter

Explanation

Kotlin properties replace Java fields + getter/setter patterns. You can customize access with get() and set(value) blocks.

33

What does @JvmStatic do on a companion object function?

B

Correct Answer

Generates a true static JVM method, allowing Java callers to invoke it without a companion reference

Explanation

@JvmStatic on a companion object function generates a static method in the class bytecode for seamless Java interoperability.

34

What is the Nothing type in Kotlin?

B

Correct Answer

A type that has no instances; used for functions that never return (e.g., throw or infinite loops)

Explanation

Functions returning Nothing always throw an exception or loop forever. It is a subtype of all types, useful for throw expressions in when branches.

35

How does Kotlin smart cast work?

B

Correct Answer

After an is type check, the compiler automatically treats the variable as the checked type within the conditional scope

Explanation

After if (x is String) { ... }, x is automatically treated as String inside the block — no explicit cast needed.

36

What is the Kotlin Range operator ..?

C

Correct Answer

Creates an inclusive range between two values

Explanation

1..10 creates an IntRange from 1 to 10 inclusive, usable in for loops and in checks.

37

What is the difference between var and val?

C

Correct Answer

var is mutable (can be reassigned); val is read-only

Explanation

var allows reassignment; val doesn't. Note that val only prevents reference reassignment — a mutable object held by val can still be mutated.

38

How do you iterate over a list in Kotlin?

C

Correct Answer

for (item in list)

Explanation

Kotlin uses for (item in collection) for iteration, similar to Java's enhanced for loop.

39

What does the also scope function do?

B

Correct Answer

Performs side-effect actions on an object and returns the object itself; parameter is it

Explanation

also is like apply but uses it instead of this, and returns the receiver. Useful for side-effects like logging.

40

What is the use of the @Suppress annotation?

B

Correct Answer

Suppresses compiler warnings for specific rules

Explanation

@Suppress("UNCHECKED_CAST") tells the compiler to silence a specific warning for the annotated element.

41

What is a Pair in Kotlin?

B

Correct Answer

A data class holding two values, accessible via .first and .second

Explanation

Pair<A, B> is a data class with first and second properties. You can create one with Pair(a, b) or the infix to function: a to b.

1

What is a Kotlin coroutine?

B

Correct Answer

A lightweight concurrency primitive that can be suspended and resumed without blocking a thread

Explanation

Coroutines are Kotlin's mechanism for asynchronous and concurrent programming. They are cheap, can suspend at suspension points, and resume later without blocking.

2

What is the difference between suspend fun and a regular fun?

B

Correct Answer

A suspend function can be paused and resumed later; it can only be called from a coroutine or another suspend function

Explanation

The suspend modifier allows a function to use suspension points (like delay or await). The compiler transforms it into a state machine.

3

What is the difference between launch and async coroutine builders?

B

Correct Answer

launch fires-and-forgets returning a Job; async returns a Deferred<T> that can be awaited

Explanation

launch is for fire-and-forget coroutines. async is for coroutines that produce a result accessed via Deferred.await().

4

What does the inline keyword do for a higher-order function?

A

Correct Answer

Inlines the function body into the call site, avoiding lambda object allocation

Explanation

Inline functions copy their body (and the lambda bodies) to each call site at compile time, eliminating the overhead of lambda object creation and virtual dispatch.

5

What is the purpose of reified type parameters?

B

Correct Answer

To retain the generic type at runtime inside inline functions, enabling is and as checks on type parameters

Explanation

Normally, generics are erased at runtime. reified (only in inline functions) preserves the type, allowing inline fun <reified T> isOf(value: Any) = value is T.

6

What is delegation in Kotlin using the by keyword?

B

Correct Answer

Forwarding interface implementation or property access to another object automatically

Explanation

class Derived(base: Base) : Base by base delegates all Base method calls to base. Property delegation (val x by Delegate()) customizes get/set.

7

What is the lazy property delegate?

B

Correct Answer

A property whose initialization is deferred until first access

Explanation

val heavy by lazy { expensiveComputation() } only runs expensiveComputation() on the first access, caching the result for subsequent reads.

8

What does withContext(Dispatchers.IO) do in a coroutine?

B

Correct Answer

Switches the coroutine's dispatcher for a block without creating a new coroutine

Explanation

withContext suspends the current coroutine, switches to the specified dispatcher, executes the block, then resumes on the original dispatcher.

9

What is a Flow in Kotlin coroutines?

B

Correct Answer

A cold asynchronous stream of values that emits multiple values over time

Explanation

Flow<T> is a cold stream — it starts emitting only when collected. It supports operators like map, filter, and flatMap for reactive-style programming.

10

What is the difference between StateFlow and SharedFlow?

B

Correct Answer

StateFlow holds a current value and replays it to new collectors; SharedFlow is configurable and doesn't require a current value

Explanation

StateFlow is like LiveData — it always has a value and emits updates. SharedFlow is more flexible with configurable replay, buffer, and overflow strategies.

11

What does structured concurrency mean in Kotlin?

B

Correct Answer

Coroutines live within a defined scope; the scope doesn't complete until all its coroutines complete, and cancellation propagates

Explanation

Structured concurrency (via CoroutineScope) ensures coroutines don't leak: if a scope is cancelled, all its children are cancelled too.

12

What is the purpose of the operator keyword?

B

Correct Answer

To allow operator overloading by linking a function to a specific operator symbol

Explanation

operator fun plus(other: MyType) enables using + with your custom class.

13

What is a destructuring declaration?

B

Correct Answer

Unpacking a component into multiple variables: val (a, b) = pair

Explanation

val (name, age) = person unpacks the data class via component1(), component2() functions. Works for data classes, Pairs, and Map entries.

14

What does crossinline do in an inline function?

B

Correct Answer

Prohibits non-local returns from the lambda while still allowing inlining

Explanation

crossinline is needed when a lambda is invoked in a different execution context (e.g., inside another lambda) where non-local returns would be unsafe.

15

What is the difference between object and class in Kotlin?

B

Correct Answer

object is a singleton; class can be instantiated multiple times

Explanation

An object declaration creates a singleton — one instance is created lazily and shared globally. A class is a blueprint for creating multiple instances.

16

How does Kotlin's type inference work?

B

Correct Answer

The compiler deduces the type from the assigned value or return type, so explicit type annotations are often optional

Explanation

val x = 42 infers Int. val list = listOf("a") infers List<String>. The compiler analyzes the expression to determine the type.

17

What is a type alias in Kotlin?

B

Correct Answer

A new name for an existing type without creating a new type

Explanation

typealias StringList = List<String> creates an alias. Useful for shortening complex generic types but does not provide type safety.

18

What is a value class (inline class) in Kotlin?

A

Correct Answer

A class that wraps a primitive for type safety without allocation overhead at runtime

Explanation

@JvmInline value class Email(val value: String) gives type safety (Email vs String) but is represented as String in JVM bytecode, avoiding boxing.

19

What does the contract block in Kotlin allow?

B

Correct Answer

Providing the compiler hints about runtime behavior to improve smart casts and null analysis

Explanation

Contracts (kotlin.contracts) let functions declare guarantees (e.g., "if this returns true, parameter x is not null") so the compiler can perform better smart casts.

20

What is vararg in Kotlin?

B

Correct Answer

A function parameter that accepts a variable number of arguments of the same type

Explanation

fun sum(vararg numbers: Int) allows calling sum(1, 2, 3). Inside the function, numbers is an IntArray.

21

What is the spread operator * used for with vararg?

B

Correct Answer

Passing the contents of an array as individual vararg arguments

Explanation

If fun f(vararg xs: Int) and vals arr = intArrayOf(1, 2), call f(*arr) to unpack the array as individual arguments.

22

How do you handle exceptions in Kotlin?

B

Correct Answer

With try-catch-finally; all exceptions are unchecked in Kotlin

Explanation

Kotlin has no checked exceptions. try-catch is used but not enforced by the compiler. runCatching is a functional alternative returning Result.

23

What does the run scope function return?

B

Correct Answer

The result of the lambda

Explanation

run executes a lambda where this refers to the receiver and returns the lambda's result. It is useful for object initialization combined with computation.

24

What is the purpose of SupervisorJob in coroutines?

B

Correct Answer

To prevent a child coroutine failure from cancelling sibling coroutines

Explanation

With a regular Job, a failing child cancels the parent and all siblings. SupervisorJob isolates failures so only the failed child is cancelled.

25

What is channel in Kotlin coroutines?

B

Correct Answer

A coroutine-safe queue for communicating between coroutines via send and receive

Explanation

Channel<T> is like a BlockingQueue but non-blocking. Coroutines use send() to produce and receive() to consume, supporting producer-consumer patterns.

26

How does Kotlin support multiple interface implementation?

B

Correct Answer

A class can implement multiple interfaces by listing them comma-separated after the colon

Explanation

class MyClass : InterfaceA, InterfaceB, ParentClass() implements multiple interfaces and optionally extends one class.

27

What is the difference between Dispatchers.Main and Dispatchers.IO?

B

Correct Answer

Dispatchers.Main runs coroutines on the UI thread; Dispatchers.IO uses a thread pool optimized for blocking I/O

Explanation

Dispatchers.Main is the UI dispatcher. Dispatchers.IO has a large thread pool (default 64) designed for blocking I/O like network or disk operations.

28

What is kotlinx.coroutines.flow.catch operator used for?

B

Correct Answer

Handling exceptions thrown upstream in a Flow chain, allowing recovery or re-emission

Explanation

flow.catch { e -> emit(defaultValue) } handles exceptions from upstream operators. It does not catch exceptions in downstream operators.

29

What is the combine Flow operator?

B

Correct Answer

Combines the latest values from multiple flows whenever any flow emits a new value

Explanation

combine(flow1, flow2) { a, b -> a + b } re-evaluates the transform whenever either flow1 or flow2 emits. Useful for reactive UI state combination.

30

What is the difference between flatMapConcat and flatMapMerge?

B

Correct Answer

flatMapConcat processes inner flows sequentially; flatMapMerge processes them concurrently with configurable concurrency

Explanation

flatMapConcat waits for each inner flow to complete before starting the next. flatMapMerge starts all inner flows concurrently (default concurrency = 16).

31

What does the Kotlin by lazy(LazyThreadSafetyMode.NONE) do?

B

Correct Answer

Skips thread-safety guarantees for maximum performance in single-threaded contexts

Explanation

LazyThreadSafetyMode.NONE removes synchronization overhead. Use when you are certain the property will only be accessed from one thread.

32

What is Kotlin's type-safe builder pattern?

B

Correct Answer

A DSL approach using receiver lambdas (T.() -> Unit) to create structured, readable object configuration DSLs

Explanation

html { body { p { +"Hello" } } } uses type-safe builders. Each function accepts a receiver lambda, scoping available methods to the context object.

33

What is the with scope function?

B

Correct Answer

Calls a lambda on an object passed as the first argument, with the object accessible as this; returns the lambda result

Explanation

with(textView) { text = "Hello"; textSize = 16f } is useful when calling multiple methods on the same non-nullable object.

34

What is the difference between coroutineScope and supervisorScope?

B

Correct Answer

coroutineScope cancels all children when one fails; supervisorScope lets siblings continue when one child fails

Explanation

coroutineScope propagates child failures. supervisorScope (like SupervisorJob) isolates failures — useful when parallel tasks are independent.

35

What is the purpose of Kotlin's @Volatile annotation?

B

Correct Answer

Maps to Java's volatile keyword, ensuring visibility of changes across threads without caching in CPU registers

Explanation

@Volatile var flag = false ensures reads/writes go directly to main memory, making state changes visible across threads immediately.

36

What is Kotlin's @Synchronized annotation?

B

Correct Answer

Maps to Java's synchronized method modifier, locking on the object instance for the duration of the function

Explanation

@Synchronized fun update() compiles to a synchronized method on the JVM, acquiring the monitor lock on the object before entering.

37

What is the difference between Kotlin's List and Array?

B

Correct Answer

Array is a Java array with a fixed size; List is a Kotlin collection interface with rich API and two implementations (read-only and mutable)

Explanation

Kotlin's Array maps directly to Java arrays. List/MutableList are Kotlin interfaces with richer API. Prefer List unless interop or performance requires Array.

38

What is Kotlin's buildString function?

B

Correct Answer

A concise way to build a string using a StringBuilder with an apply-like DSL: buildString { append("Hello"); append(name) }

Explanation

buildString { append("Hello, "); append(name); append("!") } is equivalent to StringBuilder().apply { ... }.toString() but cleaner.

39

What is the Kotlin Coroutines CoroutineExceptionHandler?

B

Correct Answer

A coroutine context element that handles uncaught exceptions from launch coroutines

Explanation

CoroutineExceptionHandler { _, exception -> log(exception) } is set as context: launch(handler) { }. It only handles exceptions from launch, not async (which stores them in Deferred).

40

What are Kotlin value classes used for instead of type aliases?

B

Correct Answer

Value classes create truly distinct types for type-safety while being erased to the underlying type at runtime

Explanation

@JvmInline value class Email(val value: String) creates a type distinct from String — passing a String where Email is expected is a compile error, unlike a type alias.

1

How does Kotlin implement coroutine suspension internally?

B

Correct Answer

The compiler transforms suspend functions into state machines using a Continuation callback parameter

Explanation

The Kotlin compiler desugars suspend functions into state machines with a Continuation<T> parameter. Each suspension point becomes a state; the continuation is resumed when the result is available.

2

What is the Continuation Passing Style (CPS) transformation?

B

Correct Answer

The compiler technique of adding a Continuation parameter to suspend functions to enable suspension and resumption

Explanation

CPS transformation adds an implicit Continuation<T> to every suspend function. The state machine calls continuation.resumeWith(result) when the async operation completes.

3

What is the difference between cold and hot Flows?

B

Correct Answer

Cold flows produce values on demand (new producer per collector); hot flows produce values regardless of collectors and share them

Explanation

Regular flow {} is cold — it starts fresh for each collector. StateFlow and SharedFlow are hot — they exist independently of collectors and share emissions.

4

What does noinline do in an inline function parameter?

B

Correct Answer

Marks a specific lambda parameter to not be inlined, allowing it to be stored or passed elsewhere

Explanation

In an inline function with multiple lambda parameters, noinline marks specific lambdas that should be compiled as objects (not inlined), needed when storing the lambda.

5

How does Kotlin enforce null-safety at the JVM bytecode level?

B

Correct Answer

Through @Nullable/@NotNull annotations and intrinsic null checks inserted by the compiler

Explanation

The Kotlin compiler emits intrinsic null-check bytecode (Intrinsics.checkNotNull) for non-null parameter receivers, plus @Nullable/@NonNull annotations for Java interop.

6

What is the purpose of Kotlin's arrow (->) in a function type?

B

Correct Answer

In type notation (A) -> B, it separates parameter types from the return type

Explanation

(Int, String) -> Boolean is a function type taking Int and String and returning Boolean. The -> separates parameter types from the return type.

7

What is Kotlin Multiplatform (KMP) and what does it share?

B

Correct Answer

A framework for sharing business logic (models, repositories, use-cases) across JVM, JS, and Native targets from a common source set

Explanation

KMP allows a commonMain source set to target Android (JVM), iOS (Kotlin/Native), Web (Kotlin/JS), and Desktop. Platform-specific implementations use expect/actual.

8

What are expect and actual declarations in KMP?

B

Correct Answer

expect declares an API in common code; actual provides a platform-specific implementation in each target

Explanation

expect class Platform() declares a type in commonMain. Each platform (androidMain, iosMain) provides actual class Platform() with its implementation.

9

How does Kotlin's coroutine Scope cancellation propagate?

B

Correct Answer

Cancelling a scope cancels all its children; each child throws CancellationException at its next suspension point

Explanation

Cancellation is cooperative. Cancelling a Job propagates to all descendants. Suspending functions (like delay) check for cancellation and throw CancellationException when cancelled.

10

What is the Mutex in Kotlin coroutines and how does it differ from synchronized?

B

Correct Answer

Mutex is a coroutine-aware mutual exclusion lock that suspends (not blocks) the waiting coroutine

Explanation

synchronized blocks the thread while waiting for the lock. Mutex.withLock { } suspends the coroutine at lock acquisition, freeing the thread for other coroutines.

11

What is Kotlin's tail-recursive optimization (tailrec)?

B

Correct Answer

The compiler replaces a tail-recursive function with a loop to prevent StackOverflowError

Explanation

tailrec fun factorial(n: Long, acc: Long = 1): Long is transformed by the compiler into a while loop, allowing deep recursion without stack overflow.

12

What is Kotlin's multiplatform expect/actual mechanism at the compiler level?

B

Correct Answer

The compiler matches each expect declaration in commonMain to its actual implementation in platform source sets during compilation

Explanation

The Kotlin compiler resolves expect/actual linkage at compile time. If a platform source set lacks an actual for an expected declaration, compilation fails.

13

What is IR (Intermediate Representation) in the Kotlin compiler?

B

Correct Answer

A platform-neutral tree representation of Kotlin code used by the backend to generate JVM, JS, or Native output

Explanation

The Kotlin IR backend generates a common IR tree then uses backend-specific lowerings to produce JVM bytecode, JavaScript, or LLVM IR for Native targets.

14

How does Kotlin's type projection work with in/out variance?

B

Correct Answer

out T (covariant projection) allows reads but not writes; in T (contravariant projection) allows writes but restricts reads — use-site variance

Explanation

fun copy(from: Array<out T>, to: Array<in T>) — from is covariant (read-only), to is contravariant (write-only). This is use-site variance, complementing declaration-site variance.

15

What is Kotlin Symbol Processing (KSP)?

B

Correct Answer

A lightweight annotation processing API using Kotlin's compiler APIs, replacing KAPT with faster incremental processing

Explanation

KSP (Kotlin Symbol Processing) is 2x faster than KAPT (Kotlin Annotation Processing) because it processes Kotlin's model directly, avoiding Java stub generation.

16

What are Kotlin context receivers and their design intent?

B

Correct Answer

An experimental feature declaring that a function requires certain receiver types in scope, enabling capabilities without inheritance

Explanation

context(Logger, Database) fun saveUser() can only be called where both Logger and Database are in scope, enabling type-safe dependency injection.

17

What is the Kotlin compiler plugin system?

B

Correct Answer

An API for extending the compiler with custom diagnostics, code generation, or IR transformations — used by kotlinx.serialization, Compose, etc.

Explanation

Kotlin compiler plugins hook into compilation phases. kotlinx.serialization generates serializers. Compose rewrites @Composable functions. Arrow uses plugins for compile-time validation.

18

What is Kotlin/Native and how does it differ from Kotlin/JVM?

B

Correct Answer

A Kotlin backend that compiles to native machine code via LLVM, enabling standalone executables without a JVM with ARC-based memory management

Explanation

Kotlin/Native uses LLVM for native compilation. Memory is managed with ARC (Automatic Reference Counting). Coroutines use a single-threaded model by default (strict immutability for sharing).

19

What is the Kotlin coroutine's low-level Continuation API?

B

Correct Answer

The interface underlying all coroutine suspension: Continuation<T> has resumeWith(Result<T>) which is called by the runtime to resume a suspended coroutine

Explanation

Every suspend function receives an implicit Continuation parameter. When suspended, the current state is captured. When resumeWith is called, execution resumes from that state.