//定義帶屬性的enum的時候,enum類必須要有個設置屬性的構造器,和返回屬性的方法。
package com.mingwei.test;
public class EnumTest {
enum WeekDayEnum {
Mon("one"), Tue("two"), Wed("three"), Thu("four"), Fri("five"), Sat(
"six"), Sun("seven");
String value;
private WeekDayEnum(String value) {
// TODO Auto-generated constructor stub
this.value = value;
}
public String getValue(){
return value;
}
}
public static void main(String[] args) {
//在使用enumu做選擇操作的時候,要注意switch 和 case 必須是enum類,而不可以說String today = "one";否則,case無法識別Mon 和 Tue等。
//換句話說就是swith和case必須是同種類型,
switch (today) {
case Mon:
System.out.println("Let's go to school");
break;
case Tue:
System.out.println("Let's go to eat");
break;
case Wed:
System.out.println("Let's go to school again");
break;
}
}
}