我的疑问是当我运行以下程序时
public class NonStatic
{
class a
{
static int b;
}
}
编译器给出错误“内部类不能有静态声明”
好吧,然后我将其给出的“static int b”更改为“final static int b”
同样的错误,但当我写“final static int b=10”时意味着使用初始化编译器
没有提示,请任何人解释一下这背后的概念是什么。
最佳答案
设计就是如此,只需参见 Java 语言规范:Inner Classes and Enclosing Instances
An inner class is a nested class that is not explicitly or implicitly declared static. [...] Inner classes may not declare static members, unless they are compile-time constant fields (§15.28).
关于java - 关于java中的非静态类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6040459/