小编Jun*_*ail的帖子

在 switch 语句上使用 case default 返回“Switch 中的预览功能模式匹配仅适用于源级别 20 及以上”

package com.learningjava.conditionals;

public class SwitchExcercises {

    public static boolean isWeekDay(int dayNumber) {
        switch (dayNumber) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
            return true;
        case 5:
        case 6:
            return false;
        case default:
            return false;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 Eclipse 作为我的 ide。说,在默认情况下显示错误

The preview feature Pattern Matching in Switch is only available with source level 20 and above.
Run Code Online (Sandbox Code Playgroud)

使用 java-se 17。感谢您的帮助。

java switch-statement

1
推荐指数
2
解决办法
277
查看次数

标签 统计

java ×1

switch-statement ×1