我不明白为什么我不能总是从“监听器”或“处理程序”内部访问变量。
这是我的代码:
唯一的方法是使用
为什么我需要将变量声明为final才能在事件内部访问?
这是我的代码:
Button btnDownload = new Button(myparent, SWT.NONE);
btnDownload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
btnDownload.setEnabled(false); // I CAN'T
}
});
唯一的方法是使用
final
关键字进行声明:final Button btnDownload = new Button(myparent, SWT.NONE);
为什么我需要将变量声明为final才能在事件内部访问?