This is what I'm doing now. Is there a better way to access the super class?
public class SearchWidget {
private void addWishlistButton() {
final SearchWidget thisWidget = this;
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// A better way to access the super class?
// something like "this.super" ...?
workWithWidget(thisWidget);
}
}
}
}
I'm programming with Google Web Toolkit, but I think this is really a generic Java question.
You can use what is called the qualified this
.
Any lexically enclosing instance can be referred to by explicitly qualifying the keyword
this
.Let C be the class denoted by
ClassName
. Let n be an integer such that C is the n-th lexically enclosing class of the class in which the qualified this expression appears. The value of an expression of the formClassName.this
is the n-th lexically enclosing instance ofthis
(§8.1.3). The type of the expression is C. It is a compile-time error if the current class is not an inner class of class C or C itself.
In this case, you can do what Martijn suggests, and use:
workWithWidget(SearchWidget.this);
You can write the name of the outer class and then .this
. So:
workWithWidget(SearchWidget.this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With