Java enum(?????????
???????????? ???????[ 2016/1/19 10:35:33 ] ??????????????????? ???????
????????????У?????????????????“?????”?????????????????????????????“?????”?е????????????
????????????????????????????????????????“?????”????????????????????????????“?????”??
????enum ?????? enumeration?? ?? JDK 1.5 ??????????????????? java.lang ???У????????????????£?enum???????ó?????????????????????????????ó??????????????
????1??????
??????????????????????????????? public static final …… ????????????:
????public static final CONSTANT_STR = "TEST";
???????????????????????????????????????????public static final?????£?
????/**
????* ???????????
????*/
????public interface IWeekConstants {
????String MON = "Mon";
????String TUE = "Tue";
????String WED = "Wed";
????String THU = "Thu";
????String FRI = "Fri";
????String SAT = "Sat";
????String SUN = "Sun";
????}
??????????????????????????????
????public enum WeekEnum {
????MON?? TUE?? WED?? THU?? FRI?? SAT?? SUN;
????}
???????????????????????? enum ??????????????????????????? java.lang.Enum ???????java.lang.Enum ???????????????????????????? Class Enum<E extends Enum<E>>???? E ???????????????????????????????????? protected Enum(String name?? int ordinal) ?????????У??????????????????????????????????????????????????????????????????
??????????δ?????????enum??????????????7??Enum(String name?? int ordinal) ?????????????name ?????????????MON??TUE???ordinal??????????
????new Enum<EnumTest>("MON"??0);
????new Enum<EnumTest>("TUE"??1);
????new Enum<EnumTest>("WED"??2);
????????????????
????2??switch
????????????switch???????????int??char???????????????????switch?У??????????????????????????????????????????????????enum??????
enum Color{
GREEN?? YELLOW?? RED
}
public class TrafficLight {
Color color = Color.RED;
public void change() {
switch (color) {
case RED:
System.out.println("???");
break;
case YELLOW:
System.out.println("???");
break;
case GREEN:
System.out.println("???");
break;
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11