Enum Types as explained in Effective Java by Joshua Bloch

隐身守侯 提交于 2019-12-04 09:16:12

Create a Test.java file and write Test enum:

public enum Test {
    Hello
}

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 {};
}

and you can see the Test class extends from Enum and it has the public static final Hello field.

Enum is the base class for all enums. It doesn't contain constants. What contains constants are the concrete enum classes themselves. See for example the documentation for the enum Locale.Category. It does contain public static final fields for each enum constant: DISPLAY and FORMAT.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!