August 2018
Beginner
178 pages
4h 56m
English
Calling a function always incurs a slight (negligible in most cases) overhead, no matter what kind of programming language you use. And in the case of Kotlin and function types, there is also the overhead of allocating memory on the heap, since function types are objects.
To avoid this overhead, Kotlin offers the inline keyword, which can be placed before the fun keyword when declaring a function. Inlining can be described as moving the functionality of a called function to its caller function.
To see the difference between inline and normal functions, let's declare functions with same body and signature, but one will be inlined:
fun noInline(func: () -> String) { val str = func() println("Func produced: $str")}inline fun ...
Read now
Unlock full access