anlex N
03/27/2024, 11:54 AMcrossinline
, I only can use variables in the f
body, right? or how to better understand crossinline
? what is non-local returns?gildor
03/27/2024, 12:06 PMgildor
03/27/2024, 12:11 PManlex N
03/27/2024, 12:18 PMfun f
and val f
, Why use it this way?so crazy, oh my god.gildor
03/27/2024, 12:19 PMgildor
03/27/2024, 12:20 PManlex N
03/27/2024, 12:25 PMfoo
or ordinaryFunction
?Miroljub Enjaković [EpicGuy4000]
03/27/2024, 12:29 PMfoo
Miroljub Enjaković [EpicGuy4000]
03/27/2024, 12:31 PMfun foo() {
ordinaryFunction {
return@foo // ERROR: cannot make `foo` return here
}
}
fun foo() {
ordinaryFunction {
return@ordinaryFunction // Success
}
}
Here is a labeled version of that codeanlex N
03/27/2024, 12:56 PMbody
can not use return
, label syntax, and exit f
, right?Miroljub Enjaković [EpicGuy4000]
03/27/2024, 1:37 PMfun foo() {
f {
println("foo.f.body")
return@f
}
}
inline fun f(crossinline body: () -> Unit) {
val f = object: Runnable {
override fun run() = body()
}
f.run()
}
fun main() {
foo()
}