October 2019
Intermediate to advanced
434 pages
11h 54m
English
Adding the inline modifier to a higher-order function will result in all passed lambdas being inlined at the call site. However, there may be cases where this is not what you want. For these situations, we can make use of noinline.
We can add the noinline modifier to a function parameter of our higher-order function. This will indicate to the compiler to not inline that particular lambda. Let's explore this using our previous example:
inline fun safelyRun(action: () -> Unit, action2:() -> Unit) { try { action() action2() } catch (error: Throwable) { println("Caught error: ${error.message}") }}
fun main() { ...
Read now
Unlock full access