Java 20: all the news
March 26, 2023
|Oracle has released Java 20 , a new version of one of the most used programming languages in the world. Not all features integrated into this release have completed the development stage. In some cases they are in fact previews, in others they are incubating features.
Pattern matching and Record Patterns
|With regard to the innovations dedicated to coding, we first of all point out the support for pattern matching in switches . Thanks to it, productivity levels should be improved by allowing an expression to be tested against a series of patterns, each with a specific action. This is so that even complex data-oriented queries can be expressed concisely and securely.
|Still with regard to productivity, it is useful to point out the introduction of Record Pattern support . This is done by extending pattern matching to express more sophisticated data queries. Java was then enhanced with record patterns for destructuring records. Both record patterns and type patterns can be nested to allow access to more powerful and declarative forms of navigation and data processing.
New API and thread management
|Also noteworthy is the Foreign Function & Memory API preview , particularly useful when you have to develop an application intended to interact with codes and information external to the Java runtime. The Vector API , which is still in the incubation stage, could also prove particularly useful . In fact, scalar calculations have limitations in terms of performance, while vector calculations should guarantee greater reliability during compilation when performed on supported CPUs.
|Structured Concurrency is also incubating , thanks to which tasks executed in different threads should be executed as a single unit, greatly simplifying multithreaded programming. The same goes for the Virtual Threads , in preview, which should require fewer resources making it easier to create, maintain and monitor high-throughput concurrent applications.
|Finally, the Scoped Values , in incubation, with which to enable the data sharing of immutable information both in threads and between threads , deserve a mention . This setting should perform better than the local thread-based one, especially in the presence of a large number of virtual threads.