Created
November 4, 2023 04:27
-
-
Save MaksimDmitriev/9e20d3443d7f4060d1d5065079464121 to your computer and use it in GitHub Desktop.
CrossInlineSample
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
package ru.maksim.sample | |
inline fun foo(task: () -> Unit) { | |
println("Before task") | |
task() | |
println("After task") | |
} | |
fun callingFunction() { | |
foo { | |
println("Task is running") | |
return@callingFunction | |
} | |
println("After calling function") | |
} | |
inline fun foo2(crossinline task: () -> Unit) { | |
println("Before task2") | |
task() | |
println("After task2") | |
} | |
fun callingFunction2() { | |
foo2 { | |
println("Task is running") | |
// return@callingFunction2 // return not allowed here because of crossinline | |
} | |
println("After calling function") | |
} |
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 SampleTest { | |
@Test | |
fun sample() { | |
callingFunction() | |
callingFunction2() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment