//定义带属性的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;
}
}
}