How do inline functions exactly execute multiple l...
# getting-started
i
How do inline functions exactly execute multiple lines of code. As an example
with
inline function has a receiver and another function that behaves as extension function, so that receiver is able to execute that function on it self. My question is how does that inline function accept multiple lines of code that need to be executed?
Does this line of code have anything to do with my question?
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
d
It's not clear what you're asking. Why would a one line function be any different than a multiple-line function from the perspective of the compiler?
i
Well obviously, I don't understand inline function. For example when I write ->
with(item) {doSomething() doSomething()...}
Is
with
inline function called for every doSomething() that is inside of the brackets?
i
No,
with
function takes the item and invokes the entire code block passed in the lambda with item as a receiver. The code above is equivalent to something like this:
Copy code
val receiver = item
receiver.doSomething()
receiver.doSomething()
...
👍 1