Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use what is called the qualified <code>this</code>.</p> <h3><a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.8.4" rel="nofollow noreferrer">JLS 15.8.4. Qualified This</a></h3> <blockquote> <p>Any lexically enclosing instance can be referred to by explicitly qualifying the keyword <code>this</code>.</p> <p>Let <em>C</em> be the class denoted by <code>ClassName</code>. Let <em>n</em> be an integer such that <em>C</em> is the <em>n</em>-th lexically enclosing class of the class in which the qualified this expression appears. The value of an expression of the form <code>ClassName.this</code> is the <em>n</em>-th lexically enclosing instance of <code>this</code> (§8.1.3). The type of the expression is <em>C</em>. It is a compile-time error if the current class is not an inner class of class <em>C</em> or <em>C</em> itself.</p> </blockquote> <p>In this case, you can do what Martijn suggests, and use:</p> <pre><code>workWithWidget(SearchWidget.this); </code></pre> <h3>References</h3> <ul> <li><a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.8.4" rel="nofollow noreferrer">JLS 15.8.4. Qualified This</a></li> <li><a href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3" rel="nofollow noreferrer">JLS 8.1.3 Inner Classes and Enclosing Instances</a></li> </ul> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/2793151/access-outer-class-from-inner-class-why-is-it-done-this-way/">Access outer class from inner class: Why is it done this way?</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload