title: Nested functions in Java
body: <p>Are there any extensions for the Java programming language that make it possible to create nested functions?</p>
  <p>There are many situations where I need to create methods that are only used once in the context of another method or for-loop. I've been unable to accomplish this in Java so far, even though it can be done easily in JavaScript.</p>
  <p>For example, this can't be done in standard Java:</p>
  <pre><code>for(int i = 1; i &lt; 100; i++){
      times(2); // Multiply i by 2 and print i
      times(i); // Square i and then print the result
  
      public void times(int num){
  
          i *= num;
          System.out.println(i);
      }
  }
  </code></pre>