Similar to swift:S1301.
Java 14 introduced grouping multiple case
clauses with comma-separated labels (java:S6208). When the switch
ends up with only one or two case
s, java:S1301 triggers and suggests to convert this switch
to an if
statement, which is obviously not the optimal solution in terms of readability.
Code example:
switch (variable) {
case 0, 1:
doSomething();
break;
default:
doSomethingElse();
break;
}
Sonar Lint for Eclipse
7.8.0.63129
Eclipse IDE for Enterprise Java and Web Developers (includes Incubating components)
Version: 2022-12 (4.26.0)
Build id: 20221201-1913
openjdk version “17.0.6” 2023-01-17
OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10)
OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)