I don't understand why I cannot always access a variable from inside a 'listener' or 'handler'.
This is my code:
Button btnDownload = new Button(myparent, SWT.NONE);
btnDownload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
btnDownload.setEnabled(false); // I CAN'T
}
});
The only way is to declare it using the final
keyword:
final Button btnDownload = new Button(myparent, SWT.NONE);
Why do I need to declare a variable final to gain access inside an event?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…