關於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