crossinline

When your inlined function calls a function type passed to it as a parameter from a different execution context than the body of the inline function, such as a nested function call, the compiler will not allow it because the function type may have a non-local control flow. In such cases, you can add the crossinline keyword to the function type parameter to tell the compiler that a non-local control flow is not allowed. The following example compiles because we have the crossinline keyword:

fun firstFunctionType(f: () -> String) {
println(f.invoke())
}

inline fun secondFunctionType(crossinline f: () -> String) {
firstFunctionType {
f.invoke()
}
}

If you remove the crossinline keyword, the compiler will throw an error.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.178.211