🐦 Kotlin Intermediate

What is an inline function in Kotlin?

Answer

An inline function is marked with the inline modifier and has its entire body — including any passed lambda bodies — copied (inlined) to each call site at compile time. This eliminates the overhead of creating a lambda object and the virtual call, which is significant in performance-critical code called in tight loops. Beyond performance, inlining enables two features that are otherwise impossible: non-local returns (returning from the enclosing function inside a lambda) and reified type parameters (accessing generic type information at runtime). All of Kotlin's standard collection functions like filter and map are inline.