title: Local inner classes safe access to local variables of containing method
body: <p>When defining a local inner class, is it safe to access local variables of the containing method that only said class has references to. Like so:</p>
  
  <pre><code>public Bar containingMethod()
  {
      Foo foo = new Foo();
      Bar bar = new Bar()
      {
          public void baz()
          {
              System.out.println("Accessing foo: " + foo.getValue());
          }
      };
      return bar;
  };
  </code></pre>
  
  <p>In my example above I'm not sure that the class being defined has a reference to <code>foo</code>. The question is if it's safe and OK to do this or am I running the risk of <code>foo</code> being garbage collected before <code>bar.baz()</code> is called?</p>