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