自定義列舉

weixin_48264499發表於2020-12-25

語言學習

自定義列舉

/**
 * 測試列舉
 * @Author:meihongsheng
 * @Description:com.mhs.test02
 */
public class TestEnum {
    public static void main(String[] args) {
        //開發中儘量使用列舉的簡單功能
        System.out.println(Season.SPRING);
        Season season = Season.AUTUMN;
        switch (season){
            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:
                break;
        }
    }
}
enum Season{
    SPRING,SUMMER,AUTUMN,WINTER
}

相關文章