Does anyone know if code like the following: ```in...
# announcements
y
Does anyone know if code like the following:
Copy code
inline fun <T> identity(block: () -> T) = block
inline fun <T> do(block: () -> T): T = block()
fun main() {
    println(do(identity { "hello" })
}
would be optimised to basically the equivalent of this:
Copy code
fun main () {
    println("hello")
}
Or would the lambda object still be created because it is being returned by
identity
? I don't have access to an IDE right this second but this question is burning me so thought I'd ask. If anyone has the time, try pasting this code into a kotlin project then doing
Show Kotlin Bytecode
then
Decompile
and look at the Java source code to see what happens.
n
had to rewrite it to this
🙌 1
kinda hard to tell but looking at the decompiled code, it doesn't look like it's inlining
snippet.kt
🙏 1
y
Yepppp just like I expected. Thank you so much dude
Didn't realise that
do
was a keyword even huh. That's interesting I guess
It's very odd tbh that a case like this isn't inlined when it easily could be since the block never gets used in any non-inlined form
Oh wow apparently Kotlin has do while loops. TIL