enum简介

在日常开发中可能有一些东西是固定的,比如一年只有4个季节,春夏秋冬。我们可以自己定义一个类里面存放这4个季节。在jdk5之后,引入了枚举(enum)的概念,可以通过enum去定义这四个季节。

定义常量类,里面存放四季

package com.sutaoyu.usually_class;

public class String_test14 {

    //枚举
public enum Season{
Spring,Summer,Autumn,Winner;
} //常用类
public class Constant{
public static final String SPRING = "Spring";
public static final String SUMMER = "Summer";
public static final String AUTUMN = "Autumn";
public static final String WINNER = "Winner"; } public static void main(String[] args) {
System.out.println(Season.Spring); //Spring
System.out.println(Constant.SPRING); //Spring
}
}
05-11 22:45