title: Tail Call Optimisation in Java
body: <p>As of Java 8, Java does not provide Tail-Call Optimization (TCO).
  On researching about it, I came to know the <a href="https://www.youtube.com/watch?v=2y5Pv4yN0b0&amp;t=1h02m18s" rel="noreferrer">reason</a> which is:</p>
  <blockquote>
  <p>In JDK classes [...] there are a number of security sensitive methods that rely on counting stack frames between JDK library code and calling code to figure out who's calling them.</p>
  </blockquote>
  <p>However Scala, which is based on JVM, has support for Tail-Call Optimisation. Scala does tail recursion optimisation at compile time. Why can't Java use the same approach?</p>
  <p>PS: Not sure whether the latest version (Java 11 as of now) of Java now has TCO. Would be great if some who knows can share this also.</p>
  <p>Notes:</p>
  <ol>
  <li><p>I know TCO is at backlog and is of lower priority but want to know why can't Java make changes in compile time similar to Scala.</p>
  </li>
  <li><p>Java doesn't have tail call optimization for the same reason most imperative languages don't have it. Imperative loops are the preferred style of the language, and the programmer can replace tail recursion with imperative loops. (<a href="https://softwareengineering.stackexchange.com/questions/272061/why-doesnt-java-have-optimization-for-tail-recursion-at-all/272082#272082">Source</a>)</p>
  </li>
  </ol>