title: Differences between anonymous inner classes and local classes
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/714602/anonymous-vs-named-inner-classes-best-practices">Anonymous vs named inner classes? - best practices?</a>  </p>
  </blockquote>
  
  
  
    
  
  <p>When working with Java <code>Handlers</code> in general, people often use three approaches :</p>
  
  <ol>
  <li>Create a class that will implements all needed interfaces</li>
  <li>Create a <code>anonymous inner class</code></li>
  <li>Create a <code>local class</code></li>
  </ol>
  
  <p>I'm interested only about the <strong>differences between 2) and 3)</strong></p>
  
  <p>Comparing 2) to 3) we can consider the following code. In this example, <strong>only one class</strong> will be generated by the Compiler.</p>
  
  <pre class="lang-java prettyprint-override"><code>class MyHandler implements ClickHandler, DragHandler, MovedHandler
      {
          public void onClick(ClickEvent clickEvent)
          {
              // Do stuff
          }
  
          public void onMoved(MovedEvent movedEvent) {
              // Do stuff
          }
  
          public void onDrag(DragEvent event) {
              // Do stuff
          }
      }
  
      MyHandler localHandler = new MyHandler();
      button.addClickHandler(localHandler);
      something.addDragHandler(localHandler);
      that.addMovedHandler(localHandler);
  </code></pre>
  
  <p>In the following example, <strong>three inner classes will be generated</strong> by the Compiler (correct me if I'm wrong). </p>
  
  <pre class="lang-java prettyprint-override"><code>button.addClickHandler(new ClickHandler()
      {
          public void onClick(ClickEvent clickEvent)
          {
              // Do stuff
          }
      });
  something.addDragHandler(new DragHandler()
      {
          public void onDrag(DragEvent event)
          {
              // Do stuff
          }
      });
  that.addMovedHandler(new MovedHandler()
      {
          public void onMoved(MovedEvent movedEvent)
          {
              // Do stuff
          }
      });
  </code></pre>
  
  <p>My question is : Is there any other difference between these two approaches ? Is there any caveats of using one despite the other ?</p>