本文实例讲述了Java枚举类用法。分享给大家供大家参考。具体如下:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 package com.school.stereotype; public enum EventStatus { DRAFT("DRAFT", "未发布"), PUBLISHED("PUBLISHED", "已发布"); private String value; private String text; private EventStatus(String status, String desc) { value = status; text = desc; } public String getValue() { return value; } public String getText() { return text; } public static EventStatus getInstance(String status) { EventStatus[] allStatus = EventStatus.values(); for (EventStatus ws : allStatus) { if (ws.getValue().equalsIgnoreCase(status)) { return ws; } } throw new IllegalArgumentException("status值非法,没有符合课程状态的枚举对象"); } }希望本文所述对大家的java程序设计有所帮助。