What if I made an explicit reference to 'this' for use inside an inner class?
- by badp
So far, I've used this approach to access this from the scope of an inner class:
class FooManagementWindow extends JFrame {
JButton rejectFoo;
//...
void getFooAcceptingPanel(){
//...
final FooManagementWindow referenceToThis = this;
rejectFoo = new JButton("Reject");
rejectFoo.addEventListener(new EventListener() {
@Override
public void actionPerformed(ActionEvent arg) {
referenceToThis.setEnabled(false); //this requires a network call
//...
referenceToThis.setEnabled(true); //the user may resume his work
}
});
//...
}
}
However, I just learned that instead of declaring referenceToThis, a direct reference is kept for me as:
FooManagementWindow.this
I have no reason to think my less standard approach may lead to errors or weird corner cases. Or are there?