Skip to main content

Java development tools

Java™ 14 Support

Java 14 Java 14 is out and Eclipse JDT supports Java 14 for 4.16.

The release notably includes the following Java 14 features:

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

Set JDK Compliance to 14 You can set the JDK compliance to 14 and enable the preview features in Preferences > Java > Compiler:

Template to create new record You can use the new_record template to create a record in an empty .java file:

Record Creation Wizard You can create a new record using the Record creation wizard that can be opened by:
  • Right Click on the Project > New > Record
  • Right Click on the Project > New > Other and search for Record
  • Right Click on the Project > New > Other > Java > Record
The Record creation wizard comes up as shown below.

Note: In older workspaces the "Record" entry may not appear directly under the "New" menu in the Java perspective. To resolve this, either use a new workspace or launch eclipse with the option -clearPersistedState for your existing workspace.
Enable preview features You can now quickly enable the preview features on an applicable Java project by right-clicking on it and selecting Configure > Enable preview features:

You can also change the default severity (warning) of the preview features compile problem in the opened Project properties dialog:

Java Editor

Non-blocking Java code completion By default, code completions in the Java editor are now configured to be computed (when possible) in a separate non-UI thread in order to prevent UI freezes in case of long computations.

Users can restore the legacy behavior in Preferences > Java > Editor > Content Assist > Advanced by unchecking the enable non-blocking completion checkbox; integrators can change the value of the org.eclipse.jdt.ui.content_assist_noUIThread_computation to false.

Merge control workflows A new clean up has been added that merges conditions of if/else if/else that have the same blocks when it is possible.

The code in the blocks should be the same. An else block may be different and won't be merged. One condition may be made opposite to allow the merge. The conditions are merged with || to keep the control workflow the same. Parenthesis is added to avoid priority issue. Most of the brackets, formatting and comments are kept.

To select the clean up, invoke Source > Clean Up..., use a custom profile, and on the Configure... dialog select Merge conditions of if/else if/else that have the same blocks on the Unnecessary Code tab.

Preferences

For the given code:

Before

You get this after the clean up:

After

Local variable type inference A new clean up has been added that makes use of the var keyword for the local variable when it is possible and is enabled only for Java 10 and higher.

The clean up replaces the explicit variable type by var when this type can be known by the variable initialization. It also replaces the diamond operator in instance creation by a parameterized type. Eventually, it adds a suffix to initialization number literal to match the variable type. In any case, the variable type is still exactly the same.

To select the clean up, invoke Source > Clean Up..., use a custom profile, and on the Configure... dialog select Use the local variable type inference on the Code Style tab.

Preferences

For the given code:

Before

You get this after the clean up:

After

Prefer lazy logical operators A new clean up has been added that replaces eager logical operators by lazy operators when it is possible.

The clean up respectively replaces | and & by || and && when the following operands can't make side effect. Any assignments, increments, decrements, object creations or method call may cause side effect. So, in such case, it will keep the eager operator. It also leaves the binary operations as it is.

To select the clean up, invoke Source > Clean Up..., use a custom profile, and on the Configure... dialog select Use the lazy logical operator on the Code Style tab.

Preferences

For the given code:

Before

You get this after the clean up:

After

Quick fix to change return statement to yield statement in Switch Expression A quick fix has been added to convert a return statement in a Switch Expression to yield statement.

Java Formatter

Record declarations support A lot of new settings have appeared in the formatter profile to control the formatting of record declarations. They are very similar to existing settings related to other type declarations. To see them all, you can use the filter field and type in the keyword record.

Debug

Synthetic variables inspection The JDT debugger is now capable of inspecting synthetic variables which are generated by the Java compilers. One such example is debugging the following method java.util.stream.ReferencePipeline.filter(Predicate<? super P_OUT>) and inspecting the predicate variable.

Before:

Now:

Preferences

Substring Matching The content assist preference option Show Substring Matches has been removed and the feature is now always enabled.

Any application or user can still disable it using the VM property: -Djdt.codeCompleteSubstringMatch=false

Previous Up Next

Back to the top