关于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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM