Lambdas & Inline Functions
KOTLIN › Types & Classes
Drills higher-order functions, lambda mechanics, closures, and when inline saves or bloats.
Lambdas and inline functions are bread-and-butter Kotlin that interviewers use to probe how deeply you understand the language beyond syntax. Expect questions on what inlining actually does to bytecode (no function-object allocation, non-local return), the precise roles of noinline and crossinline, and the trade-off between hot-path speedups and code bloat. Strong answers connect these to real Android costs like allocation pressure and reified type parameters.
What this covers
- Function types, trailing-lambda syntax, the implicit it, and labeled returns (return@label)
- How closures capture and can mutate enclosing variables, unlike Java's effectively-final captures
- What inline does: pastes the body and lambdas at the call site, removing function-object allocation
- Non-local return from an inlined lambda, and why crossinline forbids it
- When noinline and crossinline are required and what each one restricts
- Reified type parameters and the judgment call of when inlining helps versus bloats code
Study this topic
- Lambdas & Inline Functions explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- Lambdas & Inline Functions interview questions and answers