public enum Week{ MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
SATURDAY, SUNDAY}
public static final String ADMIN = "admin";
enum Week {
ROLE_ADMIN, ROLE_MEMBER, ROLE_PRODUTER // 상수문자열
}
public static void main(String[] args) {
System.out.println("enum(열거형)");
System.out.println(Week.ROLE_ADMIN);
System.out.println(Week.ROLE_MEMBER);
System.out.println(Week.ROLE_PRODUTER);
// Week(enum)에 "ROLE_ADMIN" 있으면 반환
System.out.println(Week.valueOf("ROLE_ADMIN"));
System.out.println(Week.ROLE_MEMBER.ordinal()); // 0부터 시작
System.out.println(Week.ROLE_ADMIN.ordinal()); // 0부터 시작
Week[] weeks = Week.values();
for (Week week : weeks) {
System.out.println(week + " ");
}
}
신용권, 『혼자공부하는 자』, 한빛미디어(2023)