switch
statements with only 2 branches should be if
statements instead JAVA-W1086switch
statements that have only two arms can be better represented as if
statements.
If the intent is to add more cases later on, consider adding a // skipcq: JAVA-W1086
to
the top of the switch block to avoid reporting the issue.
switch (someInt) {
case 1 -> action1();
default -> elseAction();
}
Just use an if-else
block:
if (someInt == 1) {
action1();
} else {
elseAction();
}
This issue will not be reported for switch blocks that have multiple non-default arms.