As Java Development Kit 23 gears up for its release in September, one of its initial features is set to enhance pattern matching. Building on the progress of JDK 22, scheduled for March, which introduces previews of structured concurrency and string templates, JDK 23 aims to introduce a preview of primitive types in patterns, specifically in the contexts of instanceof and switch. This enhancement proposal reflects a commitment to refining pattern matching by enabling the use of primitive type patterns across all pattern contexts.
The proposal for JDK 23 outlines several goals, including the promotion of uniform data exploration by extending type patterns to cover all types (primitive or reference), alignment of type patterns with instanceof and aligning instanceof with safe casting. Additionally, the proposal aims to enable the use of primitive pattern type patterns in nested and top-level contexts for pattern matching. The motivation behind these goals is to remove restrictions related to primitive types, enhancing developer experience with pattern matching, instanceof, and switch, making Java more uniform and expressive. JDK 23 is expected to build on features previewed in JDK 22, including the class-file API and string templates, aligning with Oracle’s biannual release schedule for standard Java versions. The current version is JDK 21, released in September, featuring virtual threads and a generational Z garbage collector.