枚举的使用

/**
*建立枚举
*/
package com.utils;

public enum Day {
 Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
}


package com.utils;

/**
 * 枚举测试
 *
 * @author work33
 *
 */
public class EnumTest {

 private static Day d;

 public EnumTest(Day d) {
  this.d = d;
 }

 public static void main(String srgs[]) {
  Day friday = Day.Friday;
  System.out.println(friday);

  for (Day d : Day.values()) {
   System.out.println("d.ordinal()" + d.ordinal() + ": " + d);
  }

  System.out.println("enum switch>>>>>>>>>>>>>>>>>");
  EnumTest et = new EnumTest(Day.Sunday);
  switchEnum();
 }

 public static void switchEnum() {
  switch (d) {
  case Sunday:
   System.out.println("星期日");
   break;
  case Monday:
   System.out.println("星期一");
   break;
  case Tuesday:
   System.out.println("星期二");
   break;
  case Wednesday:
   System.out.println("星期三");
   break;
  case Thursday:
   System.out.println("星期四");
   break;
  case Friday:
   System.out.println("星期五");
   break;
  case Saturday:
   System.out.println("星期六");
   break;
  default:
   System.out.println("no day setted");
   break;
  }
 }
}

你可能感兴趣的:(枚举)