枚举类定义如下:
package com.qunar.enumtest;
public enum Status {
SCUUESS("1", "成功"), FAILED("2", "失败");
private String value;
private String desc;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
private Status(String value, String desc) {
this.value = value;
this.desc = desc;
}
}
使用的方式如下:
package com.qunar.enumtest;
public class StutusTest {
public static void main(String[] args) {
System.out.println(Status.SCUUESS.getValue());
System.out.println(Status.SCUUESS.getDesc());
System.out.println(Status.FAILED.getValue());
System.out.println(Status.FAILED.getDesc());
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/xlgen157387/article/details/46915727