Back to Intellij Community

SwitchLabeledRuleCanBeCodeBlock

java/java-impl/resources/inspectionDescriptions/SwitchLabeledRuleCanBeCodeBlock.html

2025.3-rc-2409 B
Original Source

Reports rules of switch expressions or enhanced switch statements with an expression body. These can be converted to code blocks.

Example:

String message = switch (errorCode) {
    case 404 -> "Not found!";
    ...
  };

After the quick-fix is applied:

String message = switch (errorCode) {
    case 404 -> {
                yield "Not found!";
            }
    ...
  };

New in 2019.1