switch
statements and expressions with too few case
labels, and suggests rewriting them as if
and
else if
statements.
Example (minimum branches == 3):
switch (expression) {
case "foo" -> foo();
case "bar" -> bar();
}
After the quick-fix is applied:
if ("foo".equals(expression)) {
foo();
} else if ("bar".equals(expression)) {
bar();
}
Configure the inspection:
Use the Minimum number of branches field to specify the minimum expected number of case
labels.