码迷,mamicode.com
首页 > 其他好文 > 详细

enum 用法

时间:2014-08-16 13:42:30      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   div   log   on   sp   

public enum WeekDay {
  SUN(1, "Sunday", "SUN"),
  MON(2, "Monday", "MON"),
  TUE(3, "Tuesday", "TUE"),
  WED(4, "Wednesday", "WED"),
  THU(5, "Thursday", "THU"),
  FRI(6, "Friday", "FRI"),
  SAT(7, "Saturday", "SAT");
  
  private String shortName;
  private String fullName;
  private int dayOfWeek;
  private WeekDay(int dayOfWeek, String name, String sname) {
    this.dayOfWeek = dayOfWeek;
    fullName = name;
    shortName = sname;
  }

  public static WeekDay getDay(int dayIndex) 
  {
    switch (dayIndex) {
    case 1: return SUN;
    case 2: return MON;
    case 3: return TUE;
    case 4: return WED;
    case 5: return THU;
    case 6: return FRI;
    case 7: return SAT;
    }
    return null;
  }

  public String getShortName() {
    return shortName;
  }
  
  public int getDayOfWeek() {
    return dayOfWeek;
  }

  @Override
  public String toString() {
    return fullName;
  }
}

 

enum 用法,布布扣,bubuko.com

enum 用法

标签:style   blog   color   os   div   log   on   sp   

原文地址:http://www.cnblogs.com/fuqiang88/p/3916299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!