which solution is better? use zero lambda or pass empty lambda as default parameter? could kotlin optimize somehow empty lambda? or create a new instance that does nothing?
class Test1(val action: () -> Unit = {})
Unfortunately, I do not understand the generated bytecode. Let's analyze
val test11 = Test1()
after decompilation gives us
private static final Test1 test11 = new Test1((Function0)null, 1, (DefaultConstructorMarker)null);
and finally how lambda is passed something like this
var1 = (Function0)null.INSTANCE;
edit: hidden questions: how does Kotlin treat an empty lambda as the default?
lambda kotlin decompiling jvm-bytecode
Paweł byszewski
source share