可能重复: Cannot refer to a non-final variable inside an inner class defined in a different method 为什么它在Java中是指在内部匿名类非final的变量是不可能的?简单的答案是“因为它被禁止”,但我想知道,为什么他们禁止这个有用的功能?也许Java有一些缺乏的能力,或者它是以“错误”的方式设计的。我想知道。
这个错误是什么意思,它为什么适用?我无法在Google中找到关于成员类和静态上下文的更多信息,或者这些意思与我的情况有关。 这里是我得到的错误: non-static variable this cannot be referenced from a static context 它指出,这条线,并在new操作: throw new ParenthesisException(); Parenthe
下面的代码不编译: class OuterClass<T> {
class BaseClass { }
class SubClass extends BaseClass { }
public void test(BaseClass myObject) {
boolean b = (myObject instanceof SubClass);