title: Access "this" from Java anonymous class
body: <p>Given the following code:</p>
  
  <pre><code>public interface Selectable {
    public void select();
  }
  
  public class Container implements Selectable {
    public void select() {
    ...
    }
    public void createAnonymousClass() {
      Selectable s = new Selectable() {
        public void select() {
          //see comment below.
        }
      };
    }
  }
  </code></pre>
  
  <p>I want to access <code>Container.select()</code> from within my anonymous class' <code>select()</code> method. However, <code>this.select()</code> would again call the anonymous class' <code>select()</code> method.</p>
  
  <p>My suggestion would be:</p>
  
  <p>Introduce a field into Container, e.g.</p>
  
  <pre><code>private Container self = this;
  </code></pre>
  
  <p>Now I can access <code>Container.select()</code> by calling <code>self.select()</code> from within the anonymous class.</p>
  
  <p>Is this a reasonable way? Or are there any better ways?</p>