Skip to main content

Java Development Tools

Java Editor

Enhance if/else to switch CleanUp The clean-up to convert an if/else-if/else block into a switch has been enhanced to support String literals and Enum constants. As before, the if/else-if/else block must have at least 3 blocks and must look for constant expressions except for the last block which can be put into the default case.

For a String variable, each if/else expression can check using the String.equals() method. For an Enum the code simply uses the == operator. Use of the || operator is allowed to check multiple values and corresponds to a fall-through in the resultant switch statement.

To use the clean-up, go to Source > Clean Up > Code Style page and select: Convert if/else if/else chain with 3 blocks min to switch.

For example, performing the clean-up on the following:

convert if/else if/else to switch

will result in:

converted if/else if/else to switch

Enhance StringBuffer to Text Block The clean-up to convert a StringBuffer or StringBuilder append sequence to Text Block has been enhanced to recognize when the instance is used to supply a String or CharSequence method argument. In the past, an explicit toString() call was required after the append sequence to trigger the clean-up if the StringBuffer or StringBuilder instance wasn't further appended or did not make other method calls that made the conversion to Text Block not possible.

To use the clean-up, go to the Java Features tab of the clean-up configuration dialog and under Java 15, select: Convert String concatenation to Text Block plus Include StringBuffer or StringBuilder concatenations.

For example, performing the clean-up on the following code which used to do nothing:

before convert to text block

will result in:

after convert to text block

Quick fix to change constructor type A new quick fix Change "constructor" to compatible type has been added as an additional solution to type mismatch problems in constructor invocations. It gives type suggestions for the right-hand side of the constructor invocation to be compatible with the left-hand side.

change constructor type

Java Compiler

Removed support for souce, target and release Java 7 and below

The following compiler options are now supported only for Java 8 and above:

    --source <release>
    --target <release>
    --release <release>
    

I.e., from Eclipse 4.33 onward, the Eclipse IDE and ecj will no longer be able to produce JRE 7 (and below) compliant byte code, as the options metioned above are supported only for Java 8+.

This is the equivalent of Java 21's javac only supporting those options for Java 8+.

Previous Up Next

Back to the top