if i have a few functions that have a default argu...
# announcements
w
if i have a few functions that have a default argument of
onComplete: () -> Unit = {}
would it be best to put this no-op function in a companion object somewhere or does kotlin automatically do any optimizations ?
k
A quick look at the generated bytecode for
Copy code
fun foo(block: () -> Unit) {
    block()
}

fun main() {
    foo {}
    foo {}
}
shows that there's not much optimization happening here, two separate classes are created to represent the
{}
. You can try looking at your exact case too.
w
@karelpeeters how do you look at the generated bytecode like that?
k
Tools > Kotlin > Show Kotlin Bytecode (> Decompile, kind of buggy)
👍 2