Is it not possible to save a lambda parameter from...
# getting-started
j
Is it not possible to save a lambda parameter from a inline function to a variable? This doesn't work:
Copy code
@PublishedApi
internal var onFinish = {}

inline fun onFinish(action: () -> Unit) {
    onFinish = action
}
s
It's not possible because lambda arguments to inline functions are themselves also inlined:
The
inline
modifier affects both the function itself and the lambdas passed to it: all of those will be inlined into the call site.
https://kotlinlang.org/docs/inline-functions.html
So at the time when the function is called, the parameter doesn't really exist. There is no lambda function to store a reference to.
e
that can be avoided with the
noinline
keyword, as documented there
or with
Copy code
inline fun onFinish(crossinline action: () -> Unit) {
    onFinish = { action() }
}
but that is definitely less clear than
noinline
j
hmm okay thanks