title: Why a non-final "local" variable cannot be used inside an inner class, and instead a non-final field of the enclosing class can?
body: <p>There are some topics on Stack Overflow on the compiler error <code>Cannot refer to a non-final variable message inside an inner class defined in a different method</code> and the solution is "declare it as final and you're done", but with this <em>theoretical</em> question I would like to inspect what is the logical reason why this code cannot compile:</p>
  
  <pre><code>private void updateStatus(String message) {
      Runnable doUpdateStatus = new Runnable() {
           public void run() {
               /* do something with message */
           }
      }
      /* do something with doUpdateStatus, like SwingUtilities.invokeLater() */
  }
  </code></pre>
  
  <p>(solution: declare <code>message</code> as final) whereas this one does:</p>
  
  <pre><code>private String enclosingClassField;
  private void updateStatus() {
      Runnable doUpdateStatus = new Runnable() {
           public void run() {
               /* do something with enclosingClassField */
           }
      }
      /* do something with doUpdateStatus, like SwingUtilities.invokeLater() */
  }
  </code></pre>
  
  <p>I'm really confused. <code>enclosingClassField</code> is not final, it can change every time many times, whereas the poor <code>message</code> argument of <code>updateStatus</code> can only change within its method body, and is instead blamed by the compiler ;)</p>
  
  <p>Even the compiler error is misleading to me. <code>Cannot refer to a non-final variable message inside an inner class defined in a different method</code>: <em>Different from what?</em> Isn't <code>message</code> defined in the same method as the inner class? Isn't <code>enclosingClassField</code> instead defined outside the method? Uhm...</p>
  
  <p>Can someone point me to the correct interpretation of this matter? Thanks.</p>