- public enum Season {
- SPRING("春天", "春暖花开"),
- SUMMER("夏天", "夏日炎炎"),
- AUTUMN("秋天", "秋高气爽"),
- WINTER("冬天", "冰天雪地");
-
- private final String seasonName;
- private final String des;
-
- Season(String seasonName, String des) {
- this.seasonName = seasonName;
- this.des = des;
- }
-
- public String getSeasonName() {
- return seasonName;
- }
-
- public String getDes() {
- return des;
- }
-
- @Override
- public String toString() {
- return "Season{" +
- "seasonName='" + seasonName + '\'' +
- ", des='" + des + '\'' +
- '}';
- }
- }
- Season[] values = Season.values();
- for (int i = 0; i < values.length; i++) {
- System.out.println(values[i]);
- }
结果
(Thread)源码示例:
- public static enum State {
- NEW,
- RUNNABLE,
- BLOCKED,
- WAITING,
- TIMED_WAITING,
- TERMINATED;
-
- private State() {
- }
- }
- Thread.State[] states = Thread.State.values();
- for (int i = 0; i < states.length; i++) {
- System.out.println(states[i]);
- }