我把你的代码放在了MyEclipse6.5里运行,发生如下报错:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot refer to a non-final variable val inside an inner class defined in a different method
at Outer.method(LocalClass.java:9)
at LocalClass.main(LocalClass.java:19)
当把val变量前面加上final后,运行正常。不知怎么回事儿。 |