Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
In this blog, we going to discuss the Inline functions in Kotlin.
Functions are the basic building blocks for the program we use to define the set of functionality inside the function. Sometimes the few lines of functionality which is used in multiple places in our program will be used inside the separate function. Only function call is made for accessing the same.
In kotlin higher-order function and lambda expression, all are stored as an object. Memory allocation for all the functions and classes and for virtual calls might introduce the runtime overhead for the log file.
We simply inline the function and instruct the CPU not to allocate the memory for the function and just copy the body of the function on the calling place.
So by using this we reduce the memory overhead as well. If you want to learn the Inline functions then this blog is for you.
We will lose access to the private variables and functions of the class. So make the inline function only for the generic functionality which will not require access to the class variable.
Simply add the inline keyword before the function like below:
On the above function we have created a generic function for formatting the date.
call the inline function same as a normal function.
Kotlin compiler does not allow us to return from the lambda expression. With the help of the inline keyword, we can return from the lambda expression itself and exit the function in the inline function call.
In this blog, we have learned about the implementation of the Inline functions in Kotlin.
For more information regarding the Inline functions in Kotlin follow the link.
Thanks for reading this blog. You can also check other blogs from here.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.