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());
}
}
λ΄
겨μΈ