🐦 Kotlin Advanced

What is the noinline modifier in Kotlin?

Answer

When a function is marked inline, all lambda parameters are inlined at the call site by default. But an inlined lambda cannot be stored in a variable, passed to a non-inline function, or captured in a closure that outlives the call. The noinline modifier on a specific lambda parameter opts that particular lambda out of inlining, treating it as a regular function object. Use noinline when you need to store a lambda reference, pass it to a non-inline function, or return it from the function. The other (non-noinline) lambdas in the same function are still inlined.