0Pricing
Kotlin Academy · Lesson

noinline and crossinline Modifiers

Control inlining behavior for specific lambda parameters in inline functions.

The Problem inline Solves — And Introduces

When a function is inline, all its lambda parameters are inlined by default. Sometimes you need a specific lambda to not be inlined — for example to store it or pass it to another non-inline function.

noinline: Keeping One Lambda as an Object

Prefix a specific lambda parameter with noinline to opt it out of inlining while keeping the rest inlined.

inline fun doWork(
    action: () -> Unit,
    noinline callback: () -> Unit   // stored, not inlined
) {
    action()                        // inlined at call site
    scheduleCallback(callback)      // passed as object — valid
}

All lessons in this course

  1. inline Functions: Eliminating Lambda Overhead
  2. noinline and crossinline Modifiers
  3. reified Type Parameters: Accessing T at Runtime
  4. Practical Reified Patterns: Parsing, DI & Serialization
← Back to Kotlin Academy