title: when to use an inline function in Kotlin?
body: <p>I know that an inline function will maybe improve performance &amp; cause the generated code to grow, but I'm not sure when it is correct to use one.</p>
  
  <pre><code>lock(l) { foo() }
  </code></pre>
  
  <blockquote>
    <p>Instead of creating a function object for the parameter and generating a call, the compiler could emit the following code. (<a href="https://kotlinlang.org/docs/reference/inline-functions.html" rel="noreferrer">Source</a>)</p>
  </blockquote>
  
  <pre><code>l.lock()
  try {
    foo()
  }
  finally {
    l.unlock()
  }
  </code></pre>
  
  <p>but I found that there is no function object created by kotlin for a non-inline function. why?</p>
  
  <pre><code>/**non-inline function**/
  fun lock(lock: Lock, block: () -&gt; Unit) {
      lock.lock();
      try {
          block();
      } finally {
          lock.unlock();
      }
  }
  </code></pre>