0
0
Kotlinprogramming~10 mins

Inline functions and performance in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an inline function in Kotlin.

Kotlin
inline fun [1](block: () -> Unit) {
    block()
}
Drag options to blanks, or click blank then click option'
AinlineFun
BrunBlock
Cexecute
DcallBlock
Attempts:
3 left
💡 Hint
Common Mistakes
Using a keyword as a function name.
Leaving the function name blank.
2fill in blank
medium

Complete the code to call the inline function with a lambda expression.

Kotlin
inlineFun {
    println([1])
}
Drag options to blanks, or click blank then click option'
A"Hello, Kotlin!"
BHello, Kotlin!
Cprintln
Dlambda
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an unquoted string causing a syntax error.
Passing a function name instead of a string.
3fill in blank
hard

Fix the error in the inline function declaration by completing the code.

Kotlin
inline fun [1](crossinline block: () -> Unit) {
    val runnable = Runnable {
        block()
    }
    runnable.run()
}
Drag options to blanks, or click blank then click option'
ArunBlock
BinlineFun
CexecuteBlock
DrunLambda
Attempts:
3 left
💡 Hint
Common Mistakes
Using different function names causing unresolved reference errors.
Omitting the 'inline' keyword.
4fill in blank
hard

Fill both blanks to create a higher-order inline function that accepts a lambda and returns its result.

Kotlin
inline fun <T> [1](block: () -> T): T {
    return block[2]()
}
Drag options to blanks, or click blank then click option'
AinlineCall
Binvoke
C()
D.invoke
Attempts:
3 left
💡 Hint
Common Mistakes
Using '()' directly after 'block' without dot notation.
Choosing a function name that is a Kotlin keyword.
5fill in blank
hard

Fill all three blanks to create an inline function with a reified type parameter and a lambda that returns a Boolean.

Kotlin
inline fun <reified [1]> [2](predicate: ([3]) -> Boolean): Boolean {
    return predicate.invoke(null as [1])
}
Drag options to blanks, or click blank then click option'
AT
BcheckType
DU
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the type parameter and lambda parameter.
Omitting 'reified' keyword.