Java 20, the next planned version of Standard Java, recently added four more recommended features, although they were previously previewed or incubated in Standard Java and are being previewed or incubated again. New proposed capabilities for Java 20, or JDK (Java Development Kit) 20, are the second preview of the record pattern, a foreign function and memory API, and virtual threads. Structured concurrency will be re-incubated in JDK 20.
These include a previously proposed capability, pattern matching for switch statements and expressions, previewed for the fourth time in the upcoming Java SE (Standard Edition) release. Although OpenJDK’s JDK 20 web page does not yet list any features for planned release, the OpenJDK Java Enhancement Proposal (JEP) index lists these five features:
- Deconstruct record values with record patterns to enhance the Java programming language. Record patterns and type patterns can be nested to enable a declarative, robust, and composable form of data navigation and processing. The goals of the proposal include extending pattern matching to express more sophisticated, composable data queries and not changing the syntax or semantics of type patterns. The main changes since the first preview of JDK 19 are the addition of support for inference of type arguments to generic record patterns, support for record patterns displayed in an extended header for statement, and removing support for named record patterns.
- The Foreign Functions and Memory API introduces an API through which Java programs can interact with code and data outside the Java runtime. The API enables Java programs to call native libraries and process native data without the fragility and dangers of JNI (Java Native Interface). The API was previously incubated in JDK versions 17 and 18 and previewed in JDK 19. Improvements since JDK 19 include integration memory segment And memory address Abstraction, an advanced Memory layout Hierarchy, and segmentation memory session in the arena And segmentscope To promote sharing of parts across maintenance boundaries.
- Virtual threads are lightweight threads that reduce the effort of writing, maintaining, and monitoring high-throughput concurrent applications. Minor changes since the first preview include a small number of API changes and deprecations fixed in JDK 19. threadgroup, Also fixed in JDK 19.
- Structured Concurrency features an API to facilitate multithreaded programming and treats multiple tasks running on different threads as a unit of work. Error-handling and cancellation are streamlined, improving reliability and increasing observability. The only change in JDK 19 is that Structured TaskScope A task is updated to support scoped value inheritance by threads created in the scope.
- Pattern matching for switch statements and expressions is viewed as a mechanism to enable concise and secure expressions of complex data-oriented queries. Previously previewed in JDK 17, JDK 18, and JDK 19, the fourth preview will enable a continued co-evolution with the record pattern, which is included as a preview in JDK 19, to continuously refine based on experience and feedback. allows Major changes to pattern matching for switch since the third preview include simplified grammar for switch labels and support for inference of type arguments for generic patterns and record patterns in switch statements and expressions. Also, an absolute switch on an enum class now throws Match exceptions rather Incompatible class change error If no switch label is applied at runtime.
Other potential features of JDK 20 include public generics and string templates. Early access builds of JDK 20 can be found here jdk.java.net.
JDK 20 is scheduled for March 21, 2023, preceded by rampdown phases in December and January, and two release candidates next February. JDK 20 is set to be a short-term feature release, with only six months of premier-level support from Oracle. JDK 21, in September 2023, will be a long-term support release, supported by multiple years of support.
Copyright © 2022 IDG Communications, Inc.