The documentation about Inline Functions declares ...
# announcements
s
The documentation about Inline Functions declares that
inline
is used as
Copy code
The inline modifier affects both the function itself and the lambdas passed to it: all of those will be inlined into the call site.

In case you want only some of the lambdas passed to an inline function to be inline, you can mark some of your function parameters with the noinline modifier:
What If I do not need to make the whole function inline but want that its passed lambdas are made inline? For example my function have private fields and to make it inline it is necessary to annotate the whole function with
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
. If a function with lambda arguments is not marked as
inline
will the compiler smart enough to inline the lambda in the function body if the only lambda usage is its invocation? https://kotlinlang.org/docs/reference/inline-functions.html
d
You can only inline a lambda parameter if the function is inlined. I'm not sure how you want the compiler to inline a lambda, but not inline the function you're calling...
s
Thank you. I see now that it is not possible to inline a lambda inside of a method because the lambda body is not known at that location.
i
Also do not use
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
. Use
@PublishedApi
+
internal
visibility for those non-public declarations that you want to call from the inline function.
s
What about if I use private variables in a function which is declared inline? Should such private variables be declared as internal instead?
d
If the function is public, they have to be either public or internal+@PublishedApi