Inspectopedia 2025.2 Help

Statement can be replaced with enhanced 'switch'

Reports switch statements that can be automatically replaced with enhanced switch statements or expressions.

Example:

double getPrice(String fruit) { // Switch statement can be replaced with enhanced 'switch' switch (fruit) { case "Apple": return 1.0; case "Orange": return 1.5; case "Mango": return 2.0; default: throw new IllegalArgumentException(); } }

After the quick-fix is applied:

double getPrice(String fruit) { return switch (fruit) { case "Apple" -> 1.0; case "Orange" -> 1.5; case "Mango" -> 2.0; default -> throw new IllegalArgumentException(); }; }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

EnhancedSwitchMigration
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Java language level migration aids | Java 14

  • Use the Show warning only if conversion to expression is possible option not to warn about conversion to switch statement.

  • Use the Maximum number of statements in one branch to convert to switch expression option warn about conversion to expression only if each branch has less than the given number of statements.

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

New in 2019.1

Inspection options

Here you can find the description of settings available for the Statement can be replaced with enhanced 'switch' inspection, and the reference of their default values.

Show warning only if conversion to expression is possible

Default value:

Selected
Maximum number of statements in one branch to convert to switch expression

Default value:

2

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection EnhancedSwitchMigration

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025