package J20250805.demo02;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo01
 * @description
 * @create 2025/8/5
 */
public class Demo01 {
    //四季
//    public static final String SPRING="春天";
//    public static final String SUMMER="夏天";
//    public static final String AUTUMN="秋天";
//    public static final String WINTER="冬天";

    public static void main(String[] args) {
        //调用枚举类中某个枚举项，使用类名.枚举项的方式
        switch (Season.SPRING){
            case SPRING:
                System.out.println("春天...");
                break;
            case SUMMER:
                System.out.println("夏天...");
                break;
            case AUTUMN:
                System.out.println("秋天...");
                break;
            case WINTER:
                System.out.println("冬天...");
                break;
            default:
                System.out.println(".........");
        }

        //输出枚举项
        System.out.println(Season.SPRING);
        //每一个枚举项其实就是枚举类型的一个对象
        Season spring = Season.SPRING;
        spring.method();
        spring.show();

        //枚举的方法
        //String name()   获取枚举项的名称
        String name = Season.SPRING.name();
        System.out.println(name);
        System.out.println("-----------------------");
        //int ordinal()   获取枚举项的索引值
        int i1 = Season.SPRING.ordinal();
        int i2 = Season.SUMMER.ordinal();
        int i3 = Season.AUTUMN.ordinal();
        int i4 = Season.WINTER.ordinal();
        System.out.println(i1);
        System.out.println(i2);
        System.out.println(i3);
        System.out.println(i4);
        //int compareTo(E o)  比较两个枚举项，返回枚举项的差值
        int compare = Season.WINTER.compareTo(Season.SPRING);
        System.out.println(compare);
        //String toString() 返回枚举常量的名称
        String s = Season.SUMMER.toString();
        System.out.println(s);
        //values()    获取所有的枚举项
        Season[] values = Season.values();
        for (Season value:values){
            System.out.println(value);
        }
        //static<T> T valueOf(Class<T> type,String name) 获取指定枚举类中的指定名称的枚举值
        Season autumn = Season.valueOf(Season.class, "AUTUMN");
        Season summer = Enum.valueOf(Season.class, "SUMMER");
        System.out.println(Season.SUMMER==summer);
        System.out.println(autumn==Season.AUTUMN);
    }

}
