Kotlin Tutorial - Inline Functions

Published: 25 September 2020
on channel: JOMO Developer
492
3

Kotlin inline functions are equivalent to inline refactoring i.e. instead of calling the function, the contents of the function are inlined. This helps in avoiding an extra function call but leads to expanded code.


Inline functions can also help improve performance when we use lambdas. Kotlin lambdas help in writing a very clear and concise code. Java equivalent of Kotlin is efficient in most of the cases. There can be some specific scenarios in which using lambdas can have some performance implications and in these cases, inline functions can be helpful.


Java equivalent of Kotlin Lambda is a "Java Class" with a "single invoke function". A new instance of the class is created and its invoke method is called. In most of the cases, the compiler will try to create a single instance of the class, but in some cases, it will create a new instance every time the lambda is passed. Let's look at some code that will bring some clarity

00:00 - Intro
00:50 - Example 1 - Normal function call
03:08 - Example 1 - Inline function call
06:02 - Example 2 - Normal function call
09:27 - Example 2 - Inline function call


On this page of the site you can watch the video online Kotlin Tutorial - Inline Functions with a duration of hours minute second in good quality, which was uploaded by the user JOMO Developer 25 September 2020, share the link with friends and acquaintances, this video has already been watched 492 times on youtube and it was liked by 3 viewers. Enjoy your viewing!