Enumeration Knowledge Summary

public enum Day{
    
    
 MONDAY, TUESDAY, WEDNESDAY
}

The above is an enumeration class java file. Same meaning as below

//使用普通方式定义日期常量
public class Day{
    
    
    public static final int MONDAY =1;
    public static final int TUESDAY=2;
    public static final int WEDNESDAY=3;
}

Instructions

public class EnumDemo {
    
    
    public static void main(String[] args){
    
     
        Day day =Day.MONDAY;//直接引用
    }
}

Enumeration constants are guaranteed in terms of type safety and convenience.
If there is a type problem, the compiler will also prompt us to improve, but it is important to remember that the value of the type represented by the enumeration must be limited, that is to say, each value can be enumerated

when adding lombok

@Getter
public enum Day{
    
    
 MONDAY("%星期一%"), TUESDAY("%星期二%"), WEDNESDAY("%星期三%")
private String dayType;
    DayType(String dayType) {
    
    
        this.dayType= dayType;
}
String a=NOT_EXIST.getDualType();

Guess you like

Origin blog.csdn.net/m0_54765221/article/details/129702281