You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A new clean-up has been created to combine two opposite boolean returns controlled by an if statement into a single return where possible.
72
+
<p>To use the clean-up, go to the <b>Code Style</b> tab of the clean-up configuration dialog under <b>Control statements</b> and select: <b>Simplify boolean if/else to single return if possible</b>.</p>
73
+
<p>For example, applying the clean-up to the following code:</p>
74
+
<p><imgsrc="images/ifelseboolean-before.png" alt="convert boolean if/else to single return before"/></p>
75
+
<p>results in:</p>
76
+
<p><imgsrc="images/ifelseboolean-after.png" alt="convert boolean if/else to single return after"/></p>
77
+
</td>
78
+
</tr>
79
+
<trid="if-else-to-switch-null-handling">
80
+
<tdclass="title"><ahref="#if-else-to-switch-null-handling">Null handling for if/else to switch clean-up</a></td>
81
+
<tdclass="content">
82
+
The if/else to switch clean-up has been enhanced to properly handle the case where the value can be null. In the if/else statement, this is handled intrinsically either by an else statement or falling through the if/else if, but when converting to a switch statement, either the switch must be embedded in an if statement to test for null or for Java 21 or above, a <b>case null</b> statement needs to be added.
83
+
<p>The clean-up is accessed on the <b>Code style</b> tab of the clean-up configuration dialog under <b>Control statements</b> and selecting: <b>Convert if/else if/else chain with 3 blocks min to switch</b>.</p>
84
+
<p>Applying the clean-up to the following code:<p>
85
+
<p><imgsrc="images/ifelse-to-switch-null-before.png" alt="convert if/else to switch before"/></p>
86
+
<p>results in the following when Java version is less than 21</p>
87
+
<p><imgsrc="images/ifelse-to-switch-null-after.png" alt="convert if/else to switch after"/></p>
88
+
<p>and results in the following when the Java release is set to 21 and up:</p>
89
+
<p><imgsrc="images/ifelse-to-switch-null-21-after.png" alt="convert if/else to switch after for Java 21 and up"/></p>
90
+
91
+
</td>
92
+
</tr>
93
+
68
94
<!-- ******************* End of Java Editor ************************************* -->
69
95
70
96
<!-- ******************* Java Views and Dialogs ************************************* -->
0 commit comments