Java 12 is here! Get to know the new features here.
New switch case
There are two big innovations regarding the switch / case function with Java 12, both are currently in the preview
status.
- The popular
Arrow syntaxcan now also be used forswitch/casestatements. This makesbreakstatements unnecessary, which is really sexy. switchstatements can now have a return value and can thus be used directly as an expression
The traditional way
|
|
The new way
|
|
Raw String literals
Another new feature which has changed directly ‘The way of coding’ raw string literals.
This is currently also a preview feature, it is now possible to easily create multiline strings or strings with special characters.
Such raw string literals are generated with backticks. The new align method even makes it possible to align
multiline strings correctly (Indents).
Sure, at first glance this is a great feature, but the ‘Real World Use-Case’ is not immediately apparent. In this way, SQL queries or similar can possibly be formatted in the future.
The traditional way
|
|
The new way
|
|
|
|
New preview feature
With Java 12 there is a new feature type called preview. If you want to use these features, you can activate them
using the command line parameter -enable-preview.
There are two things to keep in mind regarding the preview features:
- The functionality can change
- A preview feature can be promoted to an official feature or completely removed
This text was automatically translated with our golang markdown translator.