亲,因为Enum定义的时候就是abstract,在程序开发中,经常用到这种java数据类型,就把enum这个关键字做为特殊的数据类型。在eclipse中,选择enum关键字,在点击电脑右键,进入到enum的源码就会发现你要的秘密了哦。附enum源码- public abstract class Enum<E extends Enum<E>>
- implements Comparable<E>, Serializable {
- /**
- * The name of this enum constant, as declared in the enum declaration.
- * Most programmers should use the {@link #toString} method rather than
- * accessing this field.
- */
- private final String name;
- /**
- * Returns the name of this enum constant, exactly as declared in its
- * enum declaration.
- *
- * <b>Most programmers should use the {@link #toString} method in
- * preference to this one, as the toString method may return
- * a more user-friendly name.</b> This method is designed primarily for
- * use in specialized situations where correctness depends on getting the
- * exact name, which will not vary from release to release.
- *
- * @return the name of this enum constant
- */
- public final String name() {
- return name;
- }
复制代码 |