java: enum

The enumeration type is part of the new features in Java 5. It is a special data type. The reason why it is special is because it is a class type but has more special constraints than the class type, but these constraints The existence of also created the simplicity, safety and convenience of enumerated types.

Enumeration type definition:

enum Day {
    
    
    MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY, SUNDAY
}

use:

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

Guess you like

Origin blog.csdn.net/qq_41504815/article/details/112967924