Skip to content

Instantly share code, notes, and snippets.

@programming086
Created July 27, 2017 15:28
Show Gist options
  • Save programming086/528c4e63015420ca5319bc908c1d547c to your computer and use it in GitHub Desktop.
Save programming086/528c4e63015420ca5319bc908c1d547c to your computer and use it in GitHub Desktop.
Kotlin inline modifiers
class Store(val lambda: () -> Unit)
inline fun someFun(inlineLambda: () -> Unit,
noinline noinlineLambda: () -> Unit,
crossinline crossinlineLambda: () -> Unit) {
Store {
//inlineLambda cannot be used
noinlineLambda() //not inlined
crossinlineLambda() //not inlined
}
inlineLambda() //inlined
noinlineLambda() // not inlined
crossinlineLambda() //inlined
}
fun main(args: Array<String>) {
someFun({
println("Print 1")
return //it is non-local return and it is ok for inline lambda
}, {
println("Print 1")
return@someFun //non-local return is not compiled here
}) {
println("Print 3")
return@someFun //non-local return is not compiled here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment