switch statements using enum code example
Example 1: java use external enum in another class switch statement
Determine the enum value represented by the int value and then switch on the enum value.
enum GuideView {
SEVEN_DAY,
NOW_SHOWING,
ALL_TIMESLOTS
}
public void onClick(DialogInterface dialog, int which) {
GuideView whichView = GuideView.values()[which];
switch (whichView) {
case SEVEN_DAY:
...
break;
case NOW_SHOWING:
...
break;
}
}
Example 2: switch case enum java
private enum FooNum {
A,
B
}
public void foo(FooNum fooNum){
switch(fooNum){
case A:
break;
case B:
break;
default:
break;
}
}