The inline
keyword tells the Kotlin compiler to replace all occurrences of
calls to this function with the actual body of the function itself.
Without inline
, our main()
function would call this max()
function
normally. With inline
, though, it is as if the code for max()
were
in main()
itself:
val bigger = if (3 > 7) 3 else 7
This reduces some runtime overhead associated with calling a function. However, it increases the size of your compiled code if you call this function from lots of different places.
You can learn more about this in:
Tags: