What is the purpose of type-safe builders in Kotlin?
To build type hierarchies dynamically at runtime.
To create generic type aliases for improved code readability.
To enforce type safety at compile time when creating complex structures.
To cast types safely within a given scope.
How does a suspending function differ from a regular function in Kotlin?
Suspending functions are deprecated and should be replaced with regular functions.
Suspending functions are executed on separate threads, while regular functions run on the main thread.
Suspending functions can be paused and resumed, allowing for non-blocking asynchronous operations.
Suspending functions cannot return values, while regular functions can.
How do you replace all occurrences of a substring in a Kotlin String?
switch()
substitute()
replaceAll()
replace()
Which keyword is used to declare a custom exception class in Kotlin?
customException
throw
exception
try
What is the primary difference between an abstract class and an interface in Kotlin?
An interface can have properties, while an abstract class cannot.
An abstract class can only inherit from one other class, while an interface can inherit from multiple.
There is no difference; they are interchangeable.
An abstract class can have constructors, while an interface cannot.
When might it be more appropriate to choose an iterative approach over recursion in Kotlin?
When the function needs to be inlined for performance optimization.
When the problem involves manipulating immutable data structures.
When the recursive solution would be significantly more readable and concise.
When the problem can be solved more efficiently with loops, especially for large inputs.
How does the 'inline' keyword optimize function calls in Kotlin?
It creates a separate thread for the function execution.
It replaces the function call with its actual code at compile time.
It disables null safety checks within the function.
It converts the function into a lambda expression automatically.
How can you find the first element in a list that satisfies a given condition?
first()
find()
filter().first()
search()
Which keyword guarantees immutability for a collection in Kotlin?
let
val
const
var
How do you create a copy of a data class instance with modified properties in Kotlin?
Using the copy() method and specifying the properties to change.
copy()
Using the clone() method.
clone()
Data classes are immutable and cannot be copied.
By manually assigning each property to a new instance.