-
Notifications
You must be signed in to change notification settings - Fork 22
Kotlin: Inline Functions
Devrath edited this page Dec 25, 2023
·
2 revisions
- Basically, a function can be called using a function call as seen above in
normal-function
when the control flow jumps from the main function to the called function and then the control jumps back to the calling function. - In the
inline-function
just by marking the called function with theinline
keyword, the call is removed since during the compile time the entire called function is cut and pasted in the called position as seen in the right hand side of the diagram.
fun guide() {
println("Start")
SomeAction()
println("End")
}
inline fun SomeAction(){
println("Action Performed")
}
Say there is a function that is small meaning the body of the function is not too big, That time we can use inline functions.
When the body of the function is large and it is used in a lot of places, It is not a good idea to use an inline function since a large code block will be repeated in a lot of places.