About custom properties of Java enumeration types

package com.cpic.test;
/**
* Custom properties about enumeration types
* */
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;
}
}

 

test:

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());


}

}

output:

Wan
2
Wan

package com.cpic.test;
/**
* Custom properties about enumeration types
* */
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;
}
}

 

test:

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());


}

}

output:

Wan
2
Wan

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325268118&siteId=291194637