Eclipse Oxygen.3a IDE Improvements: Java 10

Three weeks after the Oxygen.3 and the Java 10 release, Oxygen.3a now adds official support for Java 10 which was previously offered only as a pre-release via the Eclipse Marketplace. Because Oxygen.3a also contains some bug fixes, an upgrade is also recommended for Java developers who do not (yet) want to use Java 10.

The main innovation and the only language change of Java 10 is the so-called Local-Variable Type Inference: within code blocks, in variable declaration, you can use var instead of the type. The specific type is determined implicitly from the assigned value. With var ArrayList<String> list = new ArrayList<>(); can be shortened to var list = new ArrayList<String>();. This is often handy (e. g. in try-with-resources statements like try (var reader = new BufferedReader(new FileReader(path))) { /*...*/ }), but in some cases it can also lead to less readable code (in my opinion e. g. in enhanced for-loops like for (var item : x.getItems()) { /*...*/ }).

var is not a keyword, just a reserved type name. This means that var can still be used as a variable name but not as a type name: int int = 1; and var int = 1; are invalid, but int var = 1; and var var = 1; are both valid Java code. Hopefully I will never have to explain to anyone why a module can be named “module” and a var can be named “var”, but an int cannot be named “int” and a class cannot be named “class” and why “module” is a valid class name whereas “var” is not. And because var is just a reserved type name, final var invar = 1; may look weird but is valid.

Nonetheless, the Eclipse developers did a great job enhancing the Eclipse Java IDE to support var. The inferred type will be shown on mouse over and in the Javadoc view, the content assist is aware of the inferred type and offers the corresponding proposals and in Mark Occurences var is handled as a substitute for the inferred type:

Furthermore, the incremental Eclipse Java compiler had to be adapted for Java 10. Unlike Oracle’s Java compiler javac the Eclipse compiler, however, does not stumble over var s=List.of("a",1).

For Java and other developers, several Eclipse Oxygen.3a IDE packages are available for download. Older versions of Oxygen will prompt you to upgrade to Oxygen.3a unless the built-in automatic update is disabled. Oxygen.3a is the last update for Eclipse Oxygen. Numerous major changes are currently being finalized for the next major release, Eclipse Photon, on June 27. If you want you can already test a pre-release of Eclipse Photon.

Happy coding!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s


%d bloggers like this: