对于类中定义的枚举,比如
class OuterClass {
public enum Method {
GET,
PUT,
POST,
DELETE;
}
}
枚举是静态嵌套类(https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html)吗?从用于引用它的语法来看,情况似乎是这样。还是非静态嵌套类(内部类)?
最佳答案
An enum declaration specifies a new enum type, a special kind of class type.
所以看起来 Oracle 的说法是枚举是类。
如果您在另一个类中声明一个枚举,那么是的,它是一个内部类。枚举总是静态的,所以是,当它在另一个类中声明时,将枚举称为静态内部类(或嵌套类)是公平的。
关于java - 类中定义的枚举是静态嵌套类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50787474/