Which solution is better? Using a nullable lambda or passing an empty lambda as a default parameter? Would kotlin somehow optimize empty lambda, or create a new instance that does nothing?
class Test1(val action: () -> Unit = {})
Unfortunately, I do not understand generated byte code. Let's analyze
val test11 = Test1()
After decompilation gives us:
private static final Test1 test11 = new Test1((Function0)null, 1, (DefaultConstructorMarker)null);
And finally, as a lambda is passed, something like this:
var1 = (Function0)null.INSTANCE;
Edit: The hidden questions is: How does Kotlin treat an empty lambda as a default value?