#Java - Code Snippets for '#Switch' - 2 code snippet(s) found |
|
Sample 1. Switch Case with Enum |  | Admin info@buggybread.com |
|
|
public enum State {
NEVADA, CALIFORNIA, WASHINGTON;
}
public static void method(States stateName) {
switch (stateName) {
case NEVADA:
System.out.println("You are in Nevada");
break;
case CALIFORNIA:
System.out.println("You are in California");
break;
case WASHINGTON:
System.out.println("You are in Washington");
break;
}
}
|
|
Like Feedback switch case switch case enum switch with enums switch and enums |
|
|
Sample 2. Internal Implementation of MinguoEra | |
|
public enum MinguoEra implements Era {
BEFORE_ROC,
ROC;
public static MinguoEra of(int minguoEra) {
switch (minguoEra) {
case 0:
return BEFORE_ROC;
case 1:
return ROC;
default:
throw new DateTimeException("Invalid era: " + minguoEra);
}
}
@Override
public int getValue() {
return ordinal();
}
}
|
|
Like Feedback MinguoEra java.time java.time.chrono internal implementation enum switch throw exception throw |
|
|