Tuğçe Aras
1 min readNov 19, 2023

--

First of all, I'm sorry for replying a little late.

What you say is correct. When we put the crossinline at the beginning of the parameter and remove it again and examine the byte code, there does not seem to be much difference. However, when we put the return statement and try it, you can see the difference.

The reason I say return is that you know crossinline does not allow this. You can try it that way and see for yourself. You can remove the "return" statement and put it again and examine the difference from the byte code side.

fun main(){

higherOrderFunction2 {

println("nocrossinline")

return

}

println("hi")

higherOrderFunction {

println("crossinline")

}

println("hello")

// noInline({

// println("noinline return")

// return

// },{

// println("crossinline return")

// return

// })

}

inline fun higherOrderFunction(crossinline printInfo: () -> Unit) {

printInfo()

}

inline fun higherOrderFunction2(printInfo: () -> Unit) {

printInfo()

}

//inline fun noInline(noinline param: () -> Unit, crossinline param2: () -> Unit){

// param()

// param2()

//}

While trying "return", the other question you actually asked is "When I put a return statement on crossinline and noinline, it doesn't give an error". You can try it in the sample code I gave.

--

--

Tuğçe Aras
Tuğçe Aras

Written by Tuğçe Aras

Android Developer at Şekerbank T.A.Ş. 💻💚 | https://bio.link/tugcearas

Responses (1)