-
@param name - The name of this enum constant, which is the identifier
-
used to declare it.
-
@param ordinal - The ordinal of this enumeration constant (its position
-
in the enum declaration, where the initial constant is assigned
-
an ordinal of zero).
*/
protected Enum(String name, int ordinal) {
this.name = name;
this.ordinal = ordinal;
}
那么对于上面SeasonEnum定义的枚举,枚举实例的name和ordinal分别是什么呢?
public enum SeasonEnum {
SPRING, SUMMER, AUTUMN, WINTER;
}
//对于春夏秋冬实例编译器通过下面的构造方法怎么创建呢?
protected Enum(String name, int ordinal) {
this.name = name;
this.ordinal = ordinal;
}
//name是实例的字符串名称,ordinal是从0开始依次+1
SPRING = new Enum(“SPRING”, 0);</