Inspectopedia Help

Labeled switch rule has redundant code block

Reports labeled rules of switch statements or switch expressions that have a redundant code block.

Example:

String s = switch (n) { case 1 -> { yield Integer.toString(n); } default -> "default"; };
String s = switch (n) { case 1 -> Integer.toString(n); default -> "default"; };

This inspection depends on the Java feature 'Enhanced 'switch' blocks' which is available since Java 14.

New in 2019.1

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.14841

Last modified: 12 March 2024