I've got a xxx.java file and it has a package level class of:
class Foo<T> {
public static int classVar = 1;
}
No problem, compiles, but if I wrap it into another class:
class Outer {
class Foo<T> {
public static int classVar = 2;
}
}
Then it doesn't compile, saying that the static
declaration of inner class Outer.foo is invalid, and static
is only allowed in declaration of constant variable.
This syntax rule looks confuse to me----let's see from the Java language perspective, what would happen if static
is allowed to be used like my program does? Will it lead to any ambiguous program? Or any Runtime problem?
Thanks for explanations!