All Java 21
Just few days left until Java 21 is generally available (September 19, 2023).
I’ve read and collected resources which discuss all the features which 21 will bring.
You can follow the schedule one the page of the OpenJDK project.
The four available JEPs
Namely, there are 4 JEPs which are final and can be used in production:
JEP 431: Sequenced collections
Enhances the Java collection framework with a Collection that contains elements in a particular order. The SequencedCollection interface has been introduced for this.
JEP 440: Record patterns
This builds on the pattern matching for instanceof and pattern matching for switch (see next point) and introduces a pattern matching for records.
JEP 441: Pattern matching for switch
Introduces the pattern matching for switch which leads to much cleaner and even faster code! Instead of this:
if (obj instanceof Integer i) {
// ...
}
else if (obj instanceof Long l) {
// ..
}
You can write this:
switch (obj) {
case Integer i -> // ...
case Long l -> // ...
}
JEP 444: Virtual threads
One of the most expected feature are virtual Threads. Oracles Java magazine wrote an article about why this concept is needed and how they differ to platform threads.
And the other ones
For the other JEPs which are in other states - like String templates or unnamed classes - check this sneak peek of the java magazine.
To Java 21 and Beyond! is a talk where Billy Korando gives deeper insights and code samples of the features served by Java 21.
The Spring Framework 6.x is heading one step closer to Java 21 and has already all features to support it implemented.
That’s it! Let’s look forward to the relase day.