本文介绍了“从内部类内部访问变量需要声明为final".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在内部类内部使用一个类的本地成员时遇到此错误.我知道将其声明为final将解决此问题,但我读到Java 8应该自动处理它,因为我将Intellij与Java 8一起使用,但它仍然无法编译.还有其他方法可以在不将其声明为final的情况下进行修复吗?谢谢.

I've got this error while trying to use a local member of one class in inner class inside.I know that declare it as final will solve the issue but I read that Java 8 should handle it automaticlly, I'm using Intellij with Java 8 and it still does not compile.Is there any other way to fix it without declare it as final?thanks.

推荐答案

如果变量有效地是 final ,则Java 8将对其进行处理.

Java 8 will handle it if the variable is effectively final.

我可以想到两种可能的解释:

I can think of two possible explanations:

  1. 该变量可能不是最终有效的.尝试显式声明为final.如果遇到编译错误(例如,说某事正在尝试修改final),则该变量实际上不是最终变量.

  1. Maybe the variable is not effectively final. Try explicitly declaring it as final. If you get a compilation error (e.g. saying that something is trying to modify the final) then the variable isn't effectively final.

也许您尚未针对Java 8正确配置Intellij和项目.例如

Maybe you haven't configured Intellij and the project properly for Java 8; e.g.

这篇关于“从内部类内部访问变量需要声明为final".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:53