https://kotlinlang.org logo
#getting-started
Title
# getting-started
j

julian

07/01/2022, 10:13 PM
A function reference passed as an argument to an inline function will not be inlined. Is that correct? That's what it looks like from the bytecode, but I'm on shaky ground when making sense of bytecode.
e

ephemient

07/01/2022, 10:20 PM
can you provide an example of what you mean?
these are both inlined:
Copy code
Unit.let(::println)
Unit.let { println(it) }
d

Dominaezzz

07/01/2022, 10:23 PM
The contents of
println
are inlined?!
e

ephemient

07/01/2022, 10:24 PM
not the contents of println, but there is no wrapper object constructed
e.g. different from
val f: (Any) -> Unit = ::println
/
val f = { println(it) }
d

Dominaezzz

07/01/2022, 10:25 PM
Ah of course.
I understand the question to be, "will the contents of
println
be inlined?"
j

julian

07/01/2022, 10:27 PM
Yup @Dominaezzz. That's what I intended to ask, but wasn't clear.
Thanks @ephemient.
println
will not be inlined. Just the call to
println
is inlined.
Haha! Actually,
println
is an inline function itself, so its content will be inlined. But, if it wasn't an inline function, its content wouldn't be inlined, even when passed as an argument (by function reference) to an inline function. Phew! 😅
s

Stephan Schroeder

07/04/2022, 7:09 AM
also check up on
noinline
and
crossinline
: https://kotlinlang.org/docs/inline-functions.html
6 Views