Inline functions

Inline functions in Kotlin and when to use them, inline getters and setters, and crossinline.

Gabriel Shanahan
The Kotlin Primer
Published in
3 min readSep 11, 2022

--

— — — — — — — — — — — — — — —

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

— — — — — — — — — — — — — — —

Tags: #FYI

This article is part of the Kotlin Primer, an opinionated guide to the Kotlin language, which is indented to help facilitate Kotlin adoption inside Java-centric organizations. It was originally written as an organizational learning resource for Etnetera a.s. and I would like to express my sincere gratitude for their support.

It is recommended to read the Introduction before moving on. Check out the Table of Contents for all articles.

Using higher order functions will quickly become second nature to you, especially once you find out for yourself how powerful this programming style is. However, there ain’t no such thing as a free lunch — if you’re writing performant code, lambdas are expensive.

Each function is an object, and it captures a closure, i.e. the variables that are defined outside the function, which are accessed in the body of the function. Memory allocations (both for function…

--

--