Youssef Shoaib [MOD]
01/22/2021, 10:07 PMinline 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:
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.nanodeath
01/22/2021, 10:11 PMnanodeath
01/22/2021, 10:12 PMnanodeath
01/22/2021, 10:12 PMYoussef Shoaib [MOD]
01/22/2021, 10:14 PMYoussef Shoaib [MOD]
01/22/2021, 10:14 PMdo
was a keyword even huh. That's interesting I guessYoussef Shoaib [MOD]
01/22/2021, 10:14 PMYoussef Shoaib [MOD]
01/22/2021, 10:17 PM