1、枚举对应英文(enumeration,简写 enum)
2、枚举是一组常量的集合
3、可以这样理解:枚举属于一种特殊的类,里面只包含一组有限的特定的对象
1、不需要提供 setXxx 方法,因为枚举类对象值通常为只读
2、对枚举对象/属性使用 final + static 共同修饰,实现底层优化
3、枚举对象名通常使用全部大写,常量的命名规范
4、枚举对象根据需要,也可以有多个属性
- package com.javase.enum_;
-
- public class Enumertaion01 {
- public static void main(String[] args) {
- System.out.println(Season.SUMMER);
- }
- }
-
- class Season {
- private String name;
- private String desc;//描述
-
- //定义了四个对象
- public final static Season SPRING = new Season("春天", "温暖");
- public final static Season SUMMER = new Season("夏天", "炎热");
- public final static Season AUTUMN = new Season("秋天", "凉爽");
- public final static Season WINTER = new Season("冬天", "寒冷");
-
- //