[英]"variable is accessed from within inner class needs to be declared final" error
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.我知道将其声明为 final 将解决问题,但我读到 Java 8 应该自动处理它,我在 Java 8 中使用 Intellij,但它仍然无法编译。 Is there any other way to fix it without declare it as final?有没有其他方法可以修复它而不将其声明为最终版本? thanks.谢谢。
I know that declare it as final will solve the issue but I read that Java 8 should handle it automatically.我知道将其声明为 final 将解决问题,但我读到 Java 8 应该自动处理它。
Java 8 will handle it if the variable is effectively final .如果变量实际上是final , Java 8 将处理它。
I can think of two possible explanations:我能想到两种可能的解释:
Maybe the variable is not effectively final .也许变量不是有效的 final 。 Try explicitly declaring it as final
.尝试将其明确声明为final
。 If you get a compilation error (eg saying that something is trying to modify the final
) then the variable isn't effectively final.如果您收到编译错误(例如,说某事正在尝试修改final
),那么该变量实际上不是最终的。
Maybe you haven't configured Intellij and the project properly for Java 8;也许您没有为 Java 8 正确配置 Intellij 和项目; eg例如
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.