Created
July 27, 2017 15:28
-
-
Save programming086/528c4e63015420ca5319bc908c1d547c to your computer and use it in GitHub Desktop.
Kotlin inline modifiers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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