Skip to content

Latest commit

 

History

History
92 lines (71 loc) · 3.5 KB

File metadata and controls

92 lines (71 loc) · 3.5 KB
title Overview of New Features in Java 22 & 23
category Java
tag
New Features in Java

JDK 23, like JDK 22, is a non-LTS (Long-Term Support) version, with Oracle providing only six months of support. The next long-term support version is JDK 25, expected to be released in September next year.

The following chart shows the number of new features and update times for each version from JDK 8 to JDK 24:

Since JDK 22 and JDK 23 share many overlapping new features, this overview will primarily focus on JDK 23, while also highlighting some features unique to JDK 22.

JDK 23 includes a total of 12 new features:

The new features in JDK 22 are as follows:

Among these, I will highlight the following three features for a detailed introduction:

JDK 23

JEP 455: Primitive Types, instanceof, and switch in Patterns (Preview)

Before JEP 455, instanceof only supported reference types, and the case labels in switch expressions and statements could only use integer literals, enum constants, and string literals.

In the preview features of JEP 455, instanceof and switch fully support all primitive types, including byte, short, char, int, long, float, double, and boolean.

// Traditional approach
if (i >= -128 && i <= 127) {
    byte b = (byte)i;
    ... b ...
}

// Improved using instanceof
if (i instanceof byte b) {
    ... b ...
}

long v = ...;
// Traditional approach
if (v == 1L) {
    // ...
} else if (v == 2L) {
    // ...
} else if (v == 10_000_000_000L) {
    // ...
}

// Using long type case labels
switch (v) {
    case 1L:
        // ...
        break;
    case 2L:
        // ...
        break;
    case 10_000_000_000L:
        // ...
        break;
    default:
        // ...
}

JEP 456: Class File API (Second Preview)

The Class File API was first previewed in JDK 22, proposed by JEP 457.

The goal of the Class File API is to provide a standardized API for parsing, generating, and transforming Java class files, replacing the previous reliance on third-party libraries (like ASM