1. 程式人生 > >Java中列舉型別 Enum

Java中列舉型別 Enum

列舉例子如下:

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;
    }
}

使用方法:

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

執行結果:
在這裡插入圖片描述