Skip to main content

Java development tools

Java™ 16 Support

Java 16 Java 16 is out and Eclipse JDT supports Java 16 in 4.20.

The release notably includes the following Java 16 features:
JEP 394: Pattern Matching for Instanceof (Final).
JEP 395: Records (Final).
JEP 397: Sealed Classes (Second Preview).

Please note that preview option should be on for preview language features. For an informal introduction of the support, please refer to Java 16 Examples wiki.

JUnit

BREE update for JDT JUnit runtime bundles The bundle required execution environment (BREE) for the org.eclipse.jdt.junit.runtime and org.eclipse.jdt.junit4.runtime bundles is now JavaSE-1.8.

Java Editor

Better type for the local variable creation quick fix The quick fix Create a new local variable has been enhanced. When it creates a variable that is the expression on which a foreach loop iterates, its type is an array of the type of the loop parameter:

For the given code:

Before

One gets:

After

Use instanceof clean up A new clean up has been added that uses an instanceof expression to check an object against a hardcoded class.

The expression must be a supertype of the targeted class.

To apply the clean up, select Use instanceof keyword instead of Class.isInstance() check box on the Code Style tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Operand factorization clean up A new clean up has been added that replaces (X && Y) || (X && Z) by (X && (Y || Y)).

The operands must be passive and primitive.

To apply the clean up, select Replace (X && Y) || (X && Z) by (X && (Y || Z)) check box on the Duplicate code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Pull out a duplicate 'if' from an if/else clean up A new clean up has been added that moves a duplicate inner if condition around an outer if condition.

The inner if condition should be common to both if/else clauses of the outer if statement.

The if conditions should be passive.

To apply the clean up, select Pull out a duplicate 'if' from an if/else check box on the Duplicate code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

One if rather than duplicate blocks that fall through clean up A new clean up has been added that merges consecutive if statements with same code block that end with a jump statement.

To apply the clean up, select Single 'if' statement rather than duplicate blocks that fall through check box on the Duplicate code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Uses String.isBlank() clean up A new clean up has been added that replaces the check of the emptiness of String.strip() by the use of String.isBlank().

It avoids the cost of the creation of a stripped string.

You may use Java 11 or higher to use it.

In order to apply this cleanup also to trim().isEmpty(), you might consider to replace trim(), which exists since the beginning of Java, with strip() that has been introduced in Java 11 together with isBlank(),

But watch out, trim() and strip() differ: trim() removes leading and trailing characters with an ASCII code up to 32, including some non white space ASCII control characters and missing some Unicode white space characters, whereas strip() removes all and only leading and trailing white space.

To apply the clean up, select String.isBlank() rather than String.strip().isEmpty() check box on the Optimization tab (the Performance tab in Eclipse 2021-09) in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

valueOf() rather than instantiation clean up A new clean up has been added that replaces unnecessary primitive wrappers instance creations by using static factory methods (valueOf()).

It dramatically improves the space performance.

To apply the clean up, select valueOf() rather than instantiation check box on the Optimization tab (the Performance tab in Eclipse 2021-09) in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Primitive rather than wrapper clean up A new clean up has been added that replaces a primitive wrapper object by the primitive type when an object is not necessary.

The variable must be not null. The result should not make more autoboxing/unboxing than the original code.

To apply the clean up, select Primitive type rather than wrapper class check box on the Optimization tab (the Performance tab in Eclipse 2021-09) in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Redundant truth clean up A new clean up has been added that directly checks boolean values instead of comparing them with true/false.

The operator can be equals, not equals or XOR. The constants can be a literal or a java.lang.Boolean constant. One operand should be primitive so no new null pointer exceptions may occur.

To apply the clean up, select Boolean value rather than comparison check box on the Unnecessary Code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Implicit comparator clean up A new clean up has been added that removes the comparator declaration if it is the default one.

The declared comparator should be an equivalent to the natural order. It removes anonymous class, lambda, Comparator.comparing(), Comparator.naturalOrder() and null. It applies on List.sort(Comparator), Collections.sort(List, Comparator), Collections.max(Collection, Comparator) and Collections.min(Collection, Comparator). If the comparator is used in the method List.sort(Comparator), the method is converted into Collections.sort(List).

To apply the clean up, select Use implicit comparator when possible check box on the Unnecessary Code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Initialize array with curly clean up A new clean up has been added that replaces the new instance syntax by curly brackets to create an array.

It must be an initialization of a declaration. The declaration must have the same type.

To apply the clean up, select Create array with curly when possible check box on the Unnecessary Code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Remove variable assignment before return clean up A new clean up has been added that removes unnecessary local variable declaration or unnecessary variable assignment before a return statement.

An explicit type is added for arrays.

To apply the clean up, select Remove variable assignment before return check box on the Unnecessary Code tab in your clean up profile.

Preferences

For the given code:

Before

One gets:

After

Replace System.getProperty() calls clean up A new clean up has been added that replaces certain System.getProperty() calls with alternative Java method calls or constants instead. Using these calls/constants may end up using system defaults (e.g. system default file separator) and thus can no longer be overridden at runtime.

To apply the clean up, select Replace system property with constant check box on the Java Feature tab in your clean up profile. This enables you to check one or more sub-options: File separator, Path separator, Line separator, File encoding, or Boolean property. The last option is used for arbitrary boolean options specified by -Dsome-arbitrary-option.

Preferences

For the given code:

Before

One gets:

After

Java Views and Dialogs

Differentiate search filter for normal imports from static imports The Search view now supports a new filter dedicated for static imports. Consequently, the existing imports filter is dedicated for non-static imports only. As a result, you will now by default find statically imported references of a class or an interface.

screenshot showing a static import search filter

Create module-info.java option during New Java Project creation Create module-info.java option has been moved to the first page of New Java Project creation wizard. This option will be enabled only for Java projects with JRE 9 or above. New Java Project creation wizard will also remember the previous choice made by the user and select this option by default accordingly.

screenshot showing a static import search filter

Default Java cleanup profile of Eclipse has been updated The default cleanup profile of the Java development tools has been updated to include more cleanups. All included cleanups have been well tested and proven to be stable in the Eclipse code base. Please see the preference under Java > Clean-up for details.

screenshot showing a the new cleanup profile

Debug

Copy Run Configuration item details A new Copy button has been added to the Dependencies/Classpath tab of Run Configuration dialog. This can be used to copy the details of the selected item.

screenshot showing new menu

Debug hover for chain of variables When hovering over chain of variables, the debug hover will now show the variable value under the cursor.

hover popup on variable

It even works for array length.

hover popup on array length

Previous Up Next

Back to the top