Java 14 is out – not declaring war on boilerplate or anything

Quarkus Java containers

Oracle has pronounced Java 14 to be generally available, pushing JDK 14 into the open with new features such as records and pattern matching capabilities.

The version came out perfectly in-tune with the project’s biannual release cadence, which was sparked by Java 9 taking more than three years before finally landing in autumn 2017.

One of the more highlighted features of the new release, pattern matching for the instanceof operator, was proposed a bit before that and is finally available for testing. The preview extends the operator to take a type test pattern instead of types only, which should help programmers to write more concise code and prevent errors stemming from the need to repeat type information as in previous constructs aiming at the same effect.

Another early access addition are records which are thought to “provide a compact syntax for declaring classes which are transparent holders for shallowly immutable data”. They are made up of a name and a state description, with representations derived from the latter. 

Records are similar to enums in that they can be described as a restricted form of class and a sort of type declaration. Through their addition, devs will finally have a way of “modeling data as data”. “Declaring war on boilerplate” meanwhile isn’t on the Java team’s agenda, even though a quick glance at what it currently takes to write a proper data carrier class might be reason enough to some to justify that stance.

Apart from that the JDK comes with a foreign-memory access API and a tool for packaging self-contained Java applications, which are currently delivered as incubator modules only.

Most of the more interesting changes are still in their preview phase, though the JDK also includes stable enhancements such as the switch expression that users could already test since JDK 12. It was meant as an extension to the regular switch, allowing its use as either a statement or an expression to pave the way for pattern matching in switch and “simplify everyday coding”.

The release also exposes JDK Flight recorder data so that it can be used by monitoring tools for example, adds a file mapping mode for non-volatile memory use, and “improves the usability of NullPointerExceptions by describing precisely which variable was null and other helpful information”.