创建enum枚举类,并根据枚举key对应的枚举value,代码如下:
/**
* 创建enum枚举类,并根据枚举key对应的枚举value
* @author Justin
*
*/
public enum EnumTest {
交易成功("S","交易成功"),
交易失败("F","交易失败");
private String key;
private String value;
private EnumTest(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
/**
*
* @param key
* @return
*/
public static String getValue(String key) {
if(null != key){
for(EnumTest enumTest : EnumTest.values()){
if(key.equals(enumTest.getKey())){
return enumTest.getValue();
}
}
}
return key;
}
public static void main(String[] args) {
System.out.println(EnumTest.getValue("S"));
System.out.println(EnumTest.getValue("F"));
}
}