Enum

ν•œμ •λœ κ°’λ§Œ κ°–λŠ” 데이터 νƒ€μž…μ„ μ—΄κ±° νƒ€μž… (Enumeration Type) 이라고 ν•œλ‹€.

  • μ„ μ–Έ

μ—΄κ±° νƒ€μž…μ„ μ„ μ–Έν•˜κΈ° μœ„ν•΄μ„œλŠ” λ¨Όμ € μ—΄κ±° νƒ€μž…μ˜ 이름을 μ •ν•˜κ³  μ—΄κ±° μƒμˆ˜λ₯Ό κ°’μœΌλ‘œ 지정해야 ν•œλ‹€.

public enum Week { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY }
  • μ‚¬μš©

νƒ€μž… μ„ μ–Έμ‹œ enum ν‚€μ›Œλ“œλ₯Ό μ‚½μž…ν•΄μ•Ό ν•˜λ©°, String νƒ€μž… ν•„λ“œλ₯Ό μ„ μ–Έ ν•΄μ•Ό ν•œλ‹€. (μ΄λ•ŒλŠ” final private ν‚€μ›Œλ“œλ₯Ό μ„ μ–Έ)

enum Season {
  Spring("λ΄„"), SUMMER("여름"), FALL("가을"), WINTER("겨울");

  final private String name;

  Season (String part) {
    name = part;
  }

  String getName() {
    return name;
  }
}
class Test {
  public static void main(String arg[]) {
    show(Season.SPRING);
    show(Season.WINTER);
  }

  static void show (Season season) {
    System.out.println(season.getName());
  }
}
λ΄„
겨울