简体   繁体   English

在封闭的 scope 中定义的局部变量 collect 必须是最终的或有效的最终的

[英]Local variable collect defined in an enclosing scope must be final or effectively final

I'm getting an error Local variable collect defined in an enclosing scope must be final or effectively final at collect.我收到错误Local variable collect defined in an enclosing scope must be final or effectively final at collect. I tried declaring the collect at class level surrouning with final but still I'm getting same error.我尝试在 class 级别上声明collect与 final 但我仍然遇到同样的错误。

Any help is appreciated.任何帮助表示赞赏。 Thanks!!谢谢!!

my code我的代码

@Override
    public List<FinalAssessment> getFactorsChild(String pid) {
        
        //probationer fa performance 
        List<FinalAssessment> probationerFa = faAssessment.getProbationerFa(pid);
        
        //master factors
        List<FinalAssessment> factorsChild = faAssessment.getFactorsChild();
        /*
         * Setting marked performance grades to the factorschild list to show marked
         * performance grades in list
         */ 
        
        probationerFa.forEach(fa-> {
            if(fa.getGradecode()!=null) {
                collect = factorsChild.stream().
                filter(l->l.getGradecode().equals(fa.getItemcode())).
                peek(pfa-> pfa.setGradecode(fa.getGradecode())).collect(Collectors.toList());
            }
        });
        
        collect.forEach( x-> System.out.println("G code " + x.getGradecode()));
        
        return faAssessment.getFactorsChild();
    }

Inside lambda function all variable have to be final.在 lambda function 内部,所有变量都必须是最终变量。

you can create your collect variable as Atomic and then you can assign on it your list:您可以将您的收集变量创建为 Atomic,然后您可以在其上分配您的列表:

 AtomicReference<List<FinalAssessment>> collect = null;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在封闭作用域中定义的局部变量必须是最终的或有效的最终变量 - Local variable defined in an enclosing scope must be final or effectively final 在封闭 scope 中定义的局部变量迭代必须是最终的或有效的最终 - local variable iteration defined in an enclosing scope must be final or effectively final 在封闭 scope 中定义的局部变量 ObjList 必须是最终的或有效的最终 - Local variable ObjList defined in an enclosing scope must be final or effectively final 在封闭范围内定义的局部变量 log 必须是 final 或有效 final - Local variable log defined in an enclosing scope must be final or effectively final 线程:封闭范围中定义的局部变量必须是final或有效的final - Threads: Local variable defined in an enclosing scope must be final or effectively final 我在封闭作用域中定义的局部变量必须是最终的或有效的最终变量 - Local variable i defined in an enclosing scope must be final or effectively final Java 8 显示此错误。 在封闭作用域中定义的局部变量 itemList 必须是 final 或有效 final - Java 8 shows this error. Local variable itemList defined in an enclosing scope must be final or effectively final Java 定时器:在封闭 scope 中定义的局部变量计数必须是最终的或有效的最终 - Java Timer: local variable count defined in an enclosing scope must be final or effectively final 封闭范围中定义的局部变量textfeild_1必须是final还是有效的final? - local variable textfeild_1 defined in an enclosing scope must be final or effectively final? 计时器错误的int值:在封闭范围内定义的局部变量ans必须是final或有效的final - int for timer error: Local variable ans defined in an enclosing scope must be final or effectively final
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM