title: Are all final variables captured by anonymous classes?
body: <p>I thought I knew the answer to this, but I can't find any confirmation after an hour or so of searching.</p>
  
  <p>In this code:</p>
  
  <pre><code>public class Outer {
  
      // other code
  
      private void method1() {
          final SomeObject obj1 = new SomeObject(...);
          final SomeObject obj2 = new SomeObject(...);
          someManager.registerCallback(new SomeCallbackClass() {
              @Override
              public void onEvent() {
                   System.out.println(obj1.getName());
              }
          });
      }
  }
  </code></pre>
  
  <p>Assume that <code>registerCallback</code> saves its parameter somewhere, so that the object of the anonymous subclass will live for a while.  Obviously this object has to maintain a reference to <code>obj1</code> so that <code>onEvent</code> will work if it is called.</p>
  
  <p>But given that the object doesn't use <code>obj2</code>, does it still maintain a reference to <code>obj2</code>, so that <code>obj2</code> can't be garbage-collected while the object lives?  I was under the impression that <em>all</em> visible <code>final</code> (or effectively final) local variables and parameters were captured and thus couldn't be GC'ed as long as the object was alive, but I can't find anything that says one way or the other.</p>
  
  <p>Is it implementation-dependent?</p>
  
  <p>Is there a section in the JLS that answers this?  I wasn't able to find the answer there.</p>