Cannot refer to the non-final local variable user defined in an enclosing scope

(1)首先该错误只会在 JDK 1.7 版本及其以前如果要在匿名内部类中报出,解决办法为在传入的参数前面增加final修饰,但如果在JDK 如果变更为1.8版本及其以后,该异常就不存在了。

(2)如何查看项目JDK版本环境:

  项目选中,右键单击 --> Build Path --> Configer Build Path --> Java Compiler --> 查看 JDK Compliance 一栏查看版本

  注:把勾取消掉就可以重新选择JDK版本

Cannot refer to the non-final local variable user defined in an enclosing scope

上一篇:local variable 'xxx' referenced before assignment


下一篇:Global & Local Variable in Python