1. 每个枚举实例定义一套自己的方法示例:
1 @AllArgsConstructor
2 public enum BroadcastTypeEnum {
3 ALL(0, "全站") {
4 @Override
5 public void doSomething() {
6 System.out.println(this.name());
7 }
8 }, REGION(1, "分区") {
9 @Override
10 public void doSomething() {
11 System.out.println("kiki");
12 }
13 };
14
15 private int code;
16 private String desc;
17
18 public abstract void doSomething();
19
20 }
2. 把string转成枚举:YourEnum enum = YourEnum.valueOf(yourString);