title: When should you use a local class in Java?
body: <p>I just discovered local classes in Java:</p>
  
  <pre><code>public final class LocalClassTest
  {
    public static void main(final String[] args) {
      for(int i = 10; i &gt; 0; i--) {
        // Local class definition--declaring a new class local to the for-loop
        class DecrementingCounter {
          private int m_countFrom;
  
          public DecrementingCounter(final int p_countFrom) {
            m_countFrom = p_countFrom;
          }
  
          public void count() {
            for (int c = m_countFrom; c &gt; 0; c--) {
              System.out.print(c + " ");
            }
            System.out.println();
          }
        }
  
        // Use the local class
        DecrementingCounter dc = new DecrementingCounter(i);
        dc.count();
      }
    }
  }
  </code></pre>
  
  <p>I did come across this comment: <a href="https://stackoverflow.com/questions/478804/advantage-of-local-classes-java/479937#479937">Advantages of Local Classes</a> which listed some great advantages of local classes over anonymous inner classes.</p>
  
  <p>My question is, it doesn't seem like there would be many cases where this technique would have advantages over NON-anonymous inner classes.  What I mean is: you would use a local class if your class is only useful inside a method's scope.  But when your methods get to the point they are so complex you need to start defining custom classes inside of them, they are probably far too complex already, and need to be split up.  At which point, your local class would have to become an inner class, right?</p>
  
  <p>What are some examples of when local classes are more desirable than inner classes, which don't involved super-complex methods (which should be avoided)?</p>