Variable should be final inside listener
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1299837/cannot-refer-to-a-non-final-variable-inside-an-inner-class-defined-in-a-differen">Cannot refer to a non-final variable inside an inner class defined in a different method</a><br>
  <a href="http://stackoverflow.com/questions/4732544/why-are-only-final-variables-accessible-in-anonymous-class">Why are only final variables accessible in anonymous class?</a>  </p>
</blockquote>



<p>Looked over in SO and google looking for an answer to this question but could not find any.</p>

<p>I have the following code:</p>

<pre><code>MyClass variable = new MyClass();
Button b = new Button();
b.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e){
         System.out.println("You clicked the button");
         variable.doSomething();
   }
});
</code></pre>

<p>The compiler returns this:</p>

<blockquote>
  <p>local variable variable is accessed from within inner class; needs to
  be declared final</p>
</blockquote>

<p>What are the technical reasons why <code>variable</code> must be final?</p>
