Null or empty lambda as default value
<p>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?</p>
<p><code>class Test1(val action: () -&gt; Unit = {})</code></p>
<p>Unfortunately, I do not understand generated byte code. Let's analyze</p>
<p><code>val test11 = Test1()</code></p>
<p>After decompilation gives us:</p>
<p><code>private static final Test1 test11 = new Test1((Function0)null, 1, (DefaultConstructorMarker)null);</code></p>
<p>And finally, as a lambda is passed, something like this:</p>
<p><code>var1 = (Function0)null.INSTANCE;</code></p>
<p>Edit:
The hidden questions is: How does Kotlin treat an empty lambda as a default value?</p>