package com.Test; import lombok.AllArgsConstructor; import lombok.Getter; //枚举的话 只能用get方法 不能用set方法 public enum Hello { /** * 折线类型:0-总参与;1-预约;2-总领课;3-总转化 */ SUM_JOIN(0, "已开跑"), APPOINTMENT(1, "预备中"), SUM_LESSON(2, "到达终点"), SUM_TRANSFER(3, "已出局") ; private int code = 0; private String value = ""; public int getCode() { return code; } public String getValue() { return value; } Hello(Integer code, String value) { this.value = value; this.code = code; } public boolean equal(Integer termType) { if (this.code == termType) { return true; } return false; } }
使用
package com.Test; public class test { public static void main(String[] args) { System.out.println(Hello.APPOINTMENT.getValue()); // 赋值后再调用方法进行判断 System.out.println(Hello.APPOINTMENT.equal(11)); // 伪代码----业务上适用的场景,有枚举的话 就不用 写这么多注解 什么0代表什么 1代表什么 // // 判断跑马状态 // if (term2.getIfStart() == 0) { // termList2.setTermType(TermTypeEnum.ENROLLING.getCode()); // } else if (term2.getIfDoing() > 0 ) { // termList2.setTermType(TermTypeEnum.CAMPING.getCode()); // } else if (term2.getIfEnd() == 0) { // termList2.setTermType(TermTypeEnum.CLOSED.getCode()); // } } }
枚举也是常量的一种
https://www.cnblogs.com/wsnan/p/11648192.html