Kotlin function declaration: equals sign before curly braces
<p>In Kotlin, the function declaration syntax allows you to write equals sign before the curly braces.</p>
<p>Consider these two examples:</p>
<ol>
<li>Without <code>=</code> sign:</li>
</ol>
<pre class="lang-kotlin prettyprint-override"><code>fun foo1() {
    println(&quot;baz1&quot;)
}
</code></pre>
<p>The code inside the body gets executed by just calling <code>foo1()</code>.</p>
<ol start="2">
<li>With <code>=</code> sign:</li>
</ol>
<pre class="lang-kotlin prettyprint-override"><code>fun foo2() = {
    println(&quot;baz2&quot;)
}
</code></pre>
<p>Here, when <code>foo2()</code> is called, nothing happens, but to get the body executed one can write <code>foo2()()</code>.</p>
<p>What is the difference in these two declarations and <strong>why do they behave differently?</strong></p>
<p>You can run the code using the following program:</p>
<pre class="lang-kotlin prettyprint-override"><code>fun main() {
    foo1()
    foo2()
}

/*
This code example produces the following results:
baz1
*/
</code></pre>
<hr>
<sup>This question, though having not much meaning, is [intentionally asked and answered by the author][1], because a few questions have already been posted where people got problems because of incorrect function definitions.</sup>