枚举类型如Joshua Bloch的Effective Java所述 [英] Enum Types as explained in Effective Java by Joshua Bloch
问题描述
请参阅链接。关于枚举,布洛赫先生说
Please see this link. Regarding Enums, Mr. Bloch says
Java的枚举类型是通过public static为每个
枚举常量导出一个实例的类
Java’s enum types are classes that export one instance for each enumeration constant via a public static final field.
我阅读了 Enum Class文档,但是没有public static final field ,那么上述语句如何成立。请解释。
感谢
I read the Enum Class documentation but there was no public static final field, then how does the above statement hold true. Please explain. Thanks
推荐答案
创建一个 Test.java
写测试枚举
:
public enum Test {
Hello
}
编译此类: javac Test.java
,并使用
javap Test
获取编译的类:
compile this class: javac Test.java
,and use javap Test
to get the compiled class:
public final class Test extends java.lang.Enum{
public static final Test Hello;
public static Test[] values();
public static Test valueOf(java.lang.String);
static {};
}
,您可以看到 Test
class从 Enum
中扩展,它有 public static final Hello
字段。
and you can see the Test
class extends from Enum
and it has the public static final Hello
field.
这篇关于枚举类型如Joshua Bloch的Effective Java所述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!