简体   繁体   English

错误:从内部类中访问局部变量事件; 需要宣布最终

[英]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.

相关问题 “从内部类访问变量需要声明为final”错误 - "variable is accessed from within inner class needs to be declared final" error 错误:从内部类访问局部变量 imagesLabel; 需要声明为 final (Java) - Error: local variable imagesLabel is accessed from within inner class; needs to be declared final (Java) 错误:从内部类访问局部变量 a; 需要宣布为最终 - Error: local variable a is accessed from within inner class; needs to be declared final 从内部类访问变量“ ”,需要声明为 final - Variable ' ' is accessed from within inner class, needs to be declared final 从内部 class 访问的变量需要声明为 final - Variable accessed from within inner class needs to be declared final 变量(dialogView)是从内部类中访问的,需要声明为final - Variable (dialogView) is accessed from within inner class, needs to be declared final 从内部类访问变量“i”,需要声明为 final - Variable 'i' is accessed from within inner class, needs to be declared final 变量'btnsave'是从内部类中访问的,需要声明为final - Variable 'btnsave' is accessed from within inner class, needs to be declared final Intellij不会报告从内部类内部访问了局部变量,需要将其声明为final - Intellij doesn't report that a local variable is accessed from within inner class and needs to be declared final 从内部类内部访问局部变量user_input; 需要宣布为最终 - local variable user_input is accessed from within inner class; needs to be declared final
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM