Primitives

1 post in this section

Primitive Types in Patterns (JEP 507): Pattern Match Every Type

Note: JEP 507 is a preview feature in Java 25 (3rd preview). Enable it with --enable-preview at compile and runtime. It is expected to finalize in Java 26 or 27. The Asymmetry in Pattern Matching Java 21 gave us pattern matching for switch and instanceof. It is a great feature — but it had a glaring asymmetry: it only worked with reference types. Object obj = 42; // Java 21: works fine if (obj instanceof Integer i) { System.

Continue reading »