public enum MyEnum {
ONE("一"),
TWO("二"),
THREE("三");
private final String myNum;
MyEnum(String myNum) {
this.myNum = myNum;
}
public String getMyEnum() {
return myNum;
}
}
调用
MyEnum num = MyEnum.ONE;
System.err.println(num.getMyEnum());
key,value用法
public enum MyEnum {
ONE("一","我是一"),
TWO("二","我是二"),
THREE("三","我是三");
private final String key;
private final String value;
MyEnum(String key,String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
}
调用
MyEnum num = MyEnum.ONE;
System.err.println(num.getKey());
System.err.println(num.getValue());