case
分支覆盖,因而其 default
分支决不会被接受的枚举 switch
语句或表达式。
这样的元素冗余,特别是对于 switch
表达式,因为当 case
分支没有覆盖所有枚举常量时,它们不会进行编译。
需要将语言级别配置为 14 级,才会报告 switch
表达式。
所提供的快速修复将移除 default
分支。
示例:
enum E { A, B }
int foo(E e) {
return switch (e) {
case A -> 1;
case B -> 2;
default -> 3;
};
}
在应用快速修复后:
enum E { A, B }
int foo(E e) {
return switch (e) {
case A -> 1;
case B -> 2;
};
}
使用仅报告 switch 表达式选项,仅报告 switch 表达式中的冗余 default
分支。