Learning Kotlin: inline functions

Learning Kotlin: Inline functions

fun main(args: Array<String>) {
var a = 2
println(someMethod(a, {println("Just some dummy function")}))
}
fun someMethod(a: Int, func: () -> Unit):Int {
func()
return 2*a
}
inline fun someMethod(a: Int, func: () -> Unit):Int {
func()
return 2*a
}
inline var x.fooProperty: Boolean    get() = x.fooValue == CONST_FOO    set(x) {        // set field here    }
var x.fooProperty: Booleaninline get() = x.fooValue == CONST_FOO

I hope you now have a basic understanding of inline keyword in Kotlin. Now, it is time to get your hands dirty, try coding something using inline and don’t forget to respond with your first inline function.

And as always, follow me to read more on tech, design and spirituality. Wait, don’t forget to clap if you enjoyed this post.

Author of Kotlin Programming Cookbook | Android Developer | www.rashikaranpuria.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store