[英]Error: local variable event is accessed from within inner class; needs to be declared final
I have this code to ask the user to confirm when deleting a row. 我有这段代码要求用户在删除行时确认。
@Override
public void onRemoveRecordClick(RemoveRecordClickEvent event)
{
SC.confirm("Are you sure to delete ?", new BooleanCallback() {
public void execute(Boolean value) {
if (value != null && value) {
event.cancel();
removeData(getDataAsRecordList().get(event.getRowNum()));
} else {
}
}
});
}
But I got the error local variable event is accessed from within inner class; needs to be declared final
但我得到了错误local variable event is accessed from within inner class; needs to be declared final
local variable event is accessed from within inner class; needs to be declared final
How can I fix this? 我怎样才能解决这个问题?
Make this change: 进行此更改:
public void onRemoveRecordClick(final RemoveRecordClickEvent event)
The method execute()
needs a guarantee that the variable event
is not going to disappear (be reassigned) by the time it is needed. 方法execute()
需要保证变量event
在需要时不会消失(被重新分配)。 You provide this guarantee by declaring it as final. 您通过将其声明为最终保证来提供此保证。 Now the compiler knows where to find this variable once this method needs it. 现在,一旦此方法需要,编译器就知道在哪里找到此变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.