An inline function instructs the compiler to copy the function's code and paste it directly into the call site, instead of creating a standard function call object.
inline, every lambda passed to a function creates an anonymous class object in Java bytecode, which costs memory.inline fun executeOp(op: () -> Unit) {
println("Start")
op()
println("End")
}
// Usage
executeOp { println("Working") }
Compiler output (conceptually):
println("Start")
println("Working") // The lambda body is pasted here
println("End")
Don't inline large functions, as it increases the bytecode size of your application.
Mark this when you can explain the answer in your own words.
Help fellow developers prepare for interviews
Sharing helps the Android community grow ๐