Files
openide/java/java-impl/resources/inspectionDescriptions/EnhancedSwitchMigration.html
2025-02-05 04:43:28 +00:00

44 lines
1.2 KiB
HTML

<html>
<body>
Reports <code>switch</code> statements that can be automatically replaced with enhanced <code>switch</code> statements or expressions.
<p><b>Example:</b></p>
<pre><code>
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();
}
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
double getPrice(String fruit) {
return switch (fruit) {
case "Apple" -> 1.0;
case "Orange" -> 1.5;
case "Mango" -> 2.0;
default -> throw new IllegalArgumentException();
};
}
</code></pre>
<!-- tooltip end -->
<p>
<ul>
<li>
Use the <b>Show warning only if conversion to expression is possible</b> option not to warn about conversion to <code>switch</code> statement.
</li>
<li>
Use the <b>Maximum number of statements in one branch to convert to switch expression</b> option warn about conversion to expression only
if each branch has less than the given number of statements.
</li>
</ul>
<p><small>New in 2019.1</small></p>
</body>
</html>