📜  java switch 表达式产生结果 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:45.183000             🧑  作者: Mango

代码示例1
// 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;
};