Java enum

Posted by Adam on August 24, 2022
```java import lombok.Getter; import lombok.AllArgsConstructor; @Getter @AllArgsConstructor public enum DayOfWeek { MONDAY("Monday", 1), TUESDAY("Tuesday", 2), WEDNESDAY("Wednesday", 3), THURSDAY("Thursday", 4), FRIDAY("Friday", 5), SATURDAY("Saturday", 6), SUNDAY("Sunday", 7); private String displayName; private int numericValue; } ``` ```java DayOfWeek day = DayOfWeek.MONDAY; System.out.println("Today is " + day.getDisplayName()); // 輸出:Today is Monday System.out.println("Numeric value of " + day.getDisplayName() + " is " + day.getNumericValue()); // 輸出:Numeric value of Monday is 1 ```