A function reference passed as an argument to an i...
# getting-started
j
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
can you provide an example of what you mean?
these are both inlined:
Copy code
Unit.let(::println)
Unit.let { println(it) }
d
The contents of
println
are inlined?!
e
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
Ah of course.
I understand the question to be, "will the contents of
println
be inlined?"
j
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
also check up on
noinline
and
crossinline
: https://kotlinlang.org/docs/inline-functions.html