📅  最后修改于: 2022-03-11 14:52:45.183000             🧑  作者: Mango
// Use the yield keyword to produce a result in a switch expression.
int result = switch (month) {
case JANUARY, JUNE, JULY -> 3;
case FEBRUARY, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER -> 1;
case MARCH, MAY, APRIL, AUGUST -> {
int monthLength = month.toString().length();
yield monthLength * 4;
}
default -> 0;
};