关于Java 枚举类型的自定义属性
package com.cpic.test;
/**
* 关于枚举类型自定义属性
* */
public enum Provious {
ANHUI("皖", 1),BAIJING("京" ,2);
private String value;
private int key;
private Provious(String value, int key) {
this.value = value;
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
}
测试:
package com.cpic.test;
public class Test {
public static void main(String[] args) {
System.out.println(""+Provious.ANHUI.getValue());
System.out.println(""+Provious.BAIJING.getKey());
System.out.println(""+Provious.ANHUI.getValue());
}
}
输出:
皖
2
皖