java枚举 --的使用

复制代码
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

 

 

看开发是放到这个目录下面

posted @   凯宾斯基  阅读(95)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-01-26 sql 使用变量的方法
2018-01-26 git常用命令
点击右上角即可分享
微信分享提示