当前位置: 首页 >知识百科 > 内容

js枚举类型enum用法(enum用法)

知识百科
导读 下面是一个例举的例子:public enum WeekDay { SUN(1, "Sunday", "SUN"), MON(2, "Monday", "MON"), TUE(3, "Tuesday", "TUE"),...
2024-07-16 11:52:23

下面是一个例举的例子: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; }}。

版权声明:转载此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本网联系,我们将及时更正、删除,谢谢您的支持与理解。