Table of contents
1.
Introduction
2.
Inline Function in Kotlin
2.1.
Code
2.2.
Output
3.
Non-Local Control Flow
3.1.
For example:
3.1.1.
Code
3.1.2.
Output
4.
Crossinline Keyword
4.1.
For example:
4.1.1.
Code
4.1.2.
Output
5.
Noinline 
5.1.
For example:
5.1.1.
Code
5.1.2.
Output
6.
Reified Type Parameters
6.1.
We use this to identify the type of parameter that passes during the runtime.For example:
6.1.1.
Code
6.1.2.
Output 
7.
Frequently Asked Questions
7.1.
What are lambda expressions in kotlin?
7.2.
What is a higher-order function in Kotlin?
7.3.
Is Kotlin good for App Development?
7.4.
In which fields is Kotlin used?
7.5.
What is Kotlin?
8.
Conclusion
Last Updated: Aug 13, 2025

What are Inline Functions in Kotlin?

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Android development may look hard at first. But do you know something that can make it easier? There are many programming languages for android development out there, but Kotlin is the one that makes the process easier.

Kotlin is a programming language similar to Java and was initially developed for JVM(Java Virtual Machine). Kotlin is a more concise version of Java, making some statements easier to write. It provides many more features than Java, which makes it preferable. In this blog, we will be discussing the inline function in Kotlin.

Inline functions in kotlin

Inline Function in Kotlin

An inline function in Kotlin is a higher-order function or lambda expression that is anonymous. You can use these expressions as usual functions or parameters for other functions. But sometimes, these high-order functions can increase the runtime overhead. To counter this, we use an inline function in Kotlin to improve the performance of the higher-order functions.

Inline functions tell the compiler not to allocate memory location to lambda expressions. Thus, by using the Inline function in Kotlin, you can copy the function parameters of Lambda expressions at the calling site.

Code

fun main(args: Array<String>) {  
	inlineFunction({ 
		println("applying inline function")
	})  
}    
inline fun inlineFunction(myFun: () -> Unit ) {  
	myFun()  
    print("code under inline function")  
}  

Output

code under inline function

Non-Local Control Flow

Kotlin does not allow the compiler to return from the lambda expression itself. In such cases, if we inline the lambda expression, the function where the inline was executed will return along with the lambda. These returns are located in the lambda and are called non-local returns.
 

For example:

Code

fun main(args: Array<String>) {  
	inlineFunction({ 
		println("applying inline function")return
	},
	{ 
		println("next parameter")
	})  
}  
  
inline fun inlineFunction(myFun: () -> Unit, nxtFun: () -> Unit) {  
	myFun()  
	nxtFun()  
    print("code under inline function")  
}  

Output

applying inline function

Crossinline Keyword

In the non-local return, the lambda expression is returned along with the function where it was executed. To prevent this, we can mark the lambda using crossinline. This way it will throw a compiler error if there is any return request in the lambda expression.

For example:

Code

// Crossinline function in Kotlin

fun main(args: Array<String>) {  
	inlineFunction({ println("applying inline function")  
        return 
        // compile time error  
	},{ println("next parameter")})  
}  
  
inline fun inlineFunction(crossline myFun: () -> Unit, nxtFun: () -> Unit) {  
	myFun()  
	nxtFun()  
    print("code under inline function")  
}  

Output

Shows error

Noinline 

Suppose multiple lambdas are passing through the inline identifier and you want only some of them to be inlined. In that case, you can mark the function parameters which you don't want to be inlined with noinline modifiers.
 

For example:

Code

// Noinline function in Kotlin

fun main(args: Array<String>) {  
	inlineFunctionExample({  println("applying inline function")},  
            {  println("next parameter")
     })  
  
	println("the main closing")  
}  
  
inline fun inlineFunctionExample(myFun: () -> Unit, noinline nxtFun: () -> Unit  ) {  
	myFun()  
	nxtFun()  
	println("code under inline function")  
}  

Output

the output for Noinline function

Reified Type Parameters

We use this to identify the type of parameter that passes during the runtime.
For example:

Code

// Declaring Reified Type Parameters in Inline function in Kotlin

inline fun <reified A> myExample(name: A) {
   println("Name of your website -> "+name)
   println("Type of myClass: ${A::class.java}")
}

fun main() {
   // Calling func() with String
   myExample<String>("www.codingninjas.com")

   // Calling func() with Int value
   myExample<Int>(500)

   // Calling func() with Long value
   myExample<Long>(1L)
}

Output 

The output for Reified type parameters

Frequently Asked Questions

What are lambda expressions in kotlin?

These are anonymous functions that contain no name. You can use these expressions as usual functions or parameters for other functions.

What is a higher-order function in Kotlin?

A higher-order function is a parameter that is able to take a function as an argument and can also return a function passed as lambdas.

Is Kotlin good for App Development?

Kotlin is among the top choices for app development in today’s times. It is an alternative to java, which is used by app developers extensively.

In which fields is Kotlin used?

Developers can use Kotlin for App Development and web development for various platforms like macOS, IOS, and Android.

What is Kotlin?

Kotlin is a programming language used by android developers. It is used by most developers and is an open-source language developed by JetBrains.

Conclusion

This blog discussed and explained how to use the inline function in Kotlin along with some examples. We hope that we were able to make you understand this whole concept clearly. For more information on Kotlin look at some of these related articles below:

Read many more on our platform Coding Ninjas Studio. You can also refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blogs to help other ninjas grow. 

Happy Coding!!

Live masterclass