TLDR : Java objects just got smaller, less heap usage (around 20%). G1 Garbage Collector is now the default GC
note : even if my TLDR provides the important information, please still read the article. It will be a great read
I love those write ups, been following your work for a while and I appreciate these new Java features overview a lot, thank you so much for your contributions 🫶🏻♥️
This changes the game completely for Pattern-Matching. Now, you can flatten your checks out into a single, extended switch, but you no longer have to pay the resulting tradeoff of "example chasing" for it anymore -- the compiler will do it for you!
This feature just removed the biggest weakness of Pattern-Matching, in my firm opinion.
It means when a switch statement is missing cases from your enum/pattern, the compiler will point out the missing cases. So you don't need to chase the enum in the sources/docs.
final String userFriendlyResultText =
switch (this.calculateResult(id))
{
case SUCCESS -> "Step succeeded for " + id;
case FAILURE -> "Step failed for " + id;
//case TIMEOUT -> "Step timed out for " + id; //lets say I forgot this transition.
}
;
If I switch over that enum, but forget to handle TIMEOUT, then yes, the IDE will definitely be able to tell me that I missed a case.
But consider the following example instead.
sealed interface Result
{
sealed interface Success
{
enum Transition
{
INFORMED_DELIVERY,
POSTAL,
ADDRESS_MANAGEMENT_SYSTEM,
;
}
record Progress(UUID id, Transition nextStep) implements Success {}
record Complete(UUID id, boolean sendEmail) implements Success {}
}
sealed interface Failure
{
record Timeout(UUID id, Duration timeWaited) implements Failure {}
record ExhaustedRetries(UUID id, int numAttempts) implements Failure {}
record ErroredOut(UUID id, Throwable error) implements Failure {}
}
UUID id();
}
And further consider the following switch statement.
final WorkflowAction nextStep =
switch (this.calculateResult(id))
{
case Progress(var id, INFORMED_DELIVERY) -> IV::notifyUser;
case Progress(var id, POSTAL) -> (uuid) -> Postal.getInstance().requestReview(uuid, List.<Warning>of());
case Progress(var id, ADDRESS_MANAGEMENT_SYSTEM) -> this::loadAddress;
case Complete(var id, false) -> (uuid) -> this.sendWorkflowCompletion(this.workflowFor(uuid));
case Timeout(var id, var timeWaited) -> (uuid) -> this.sendWorkflowFailure(this.workflowFor(uuid));
case ExhaustedRetries(var id, int numAttempts) -> (uuid) -> this.sendWorkflowFailure(this.workflowFor(uuid));
case ErroredOut(var id, var error) -> (uuid) -> this.sendWorkflowFailure(this.workflowFor(uuid), error);
}
;
Can you spot the missing case? Would your IDE be able to?
This feature allows the compiler to tell me any missing case, however many dimensions deep my switch statement is (with the caveat of the more dimensions taking a longer time to find).
And the above example is only a 2-3 dimensional case. Here is a 7 dimensional case -- HelltakerPathFinder logic
And /u/cowwoc, this should answer your question too. In the above example, the compiler would throw the following error message.
So do you often write multi-dimensional switch-expressions? Do you imagine you'll start writing many more soon?
I remember how hyped I was for gatherers and I imagined myself using them a lot. When they finally arrived I realized a couple of things:
Custom gatherers are sufficiently hard to read, that it's rarely the most readable way to solve any given problem
This applies doubly if your colleagues (like some of mine) would rather you not use reduce because they find it hard to follow
So you'd need a usecase in which it's not only possible to use the cool new feature but in which it's actually justified against the best possible alternative
And this seems pretty similar to me: Seems pretty cool at first, but how often is a multi-dimensional switch expression actually the best possible way to write your code, even if it is now exhaustive?
Also: Isn't the missing pattern case Complete(var id, true)?
Still, grep those Helm charts anyway; deprecated flags have a habit of becoming removed flags exactly when we least expect it.
FYI: In the JVM we deprecate flags in one release, obsolete it in the next and remove it in the third. So, you've got 12 months to fix it. For this flag, you can see that we plan to remove it in 29. { "InitiatingHeapOccupancyPercent", JDK_Version::jdk(27), JDK_Version::jdk(28), JDK_Version::jdk(29) },
Oh my, what a surprisingly good article with a little hands on as well. I love this "see for yourself" approach.
It's a bit bittersweet to read about new language features, though. On the one hand, this looks so exciting. I want to try them ASAP. But on the other hand, so much of the code is written by AI that it's like reading about something exciting for someone else...
Edit: I'm curious why I got the downvotes. I didn't offend anyone. Praised the article and added a personal note that keeps bothering me. So if you disagree, I'm happy to discuss :)
While runtime improvements like compact object headers by default are great for trimming memory overhead, what Java developers actually want comes down to day-to-day ergonomics: clean string interpolation without over-engineered templates, real language-level null safety with safecall operators instead of Optional clutter, and the long-promised flat memory layouts from Project Valhalla so our cloud bills stop getting crushed by stupid object overhead. Java has mastered runtime stability and throughput, but until writing routine application code stops feeling like an uphill battle against boilerplate compared to Kotlin or C#, everyday developer experience is going to lag behind.
93
u/gufranthakur Aug 23 '26 edited Aug 23 '26
TLDR : Java objects just got smaller, less heap usage (around 20%). G1 Garbage Collector is now the default GC
note : even if my TLDR provides the important information, please still read the article. It will be a great read
I love those write ups, been following your work for a while and I appreciate these new Java features overview a lot, thank you so much for your contributions 🫶🏻♥️
26
u/davidalayachew Aug 23 '26
I only skimmed this, but regarding "smaller tidbits", you missed a pretty big feature coming out in 27 -- Exhaustiveness Checking is getting an Example Generator.
This changes the game completely for Pattern-Matching. Now, you can flatten your checks out into a single, extended
switch, but you no longer have to pay the resulting tradeoff of "example chasing" for it anymore -- the compiler will do it for you!This feature just removed the biggest weakness of Pattern-Matching, in my firm opinion.
11
u/Life_Sink9598 Aug 23 '26
FYI: In the JVM we deprecate flags in one release, obsolete it in the next and remove it in the third. So, you've got 12 months to fix it. For this flag, you can see that we plan to remove it in 29.
{ "InitiatingHeapOccupancyPercent", JDK_Version::jdk(27), JDK_Version::jdk(28), JDK_Version::jdk(29) },19
u/ulimn Aug 23 '26 edited Aug 23 '26
Oh my, what a surprisingly good article with a little hands on as well. I love this "see for yourself" approach.
It's a bit bittersweet to read about new language features, though. On the one hand, this looks so exciting. I want to try them ASAP. But on the other hand, so much of the code is written by AI that it's like reading about something exciting for someone else...
Edit: I'm curious why I got the downvotes. I didn't offend anyone. Praised the article and added a personal note that keeps bothering me. So if you disagree, I'm happy to discuss :)
1
u/codejavadotnet Sep 24 '26
I'm lagging behind, so many Java updates.
1
u/Itchy_Association_46 Sep 24 '26
While runtime improvements like compact object headers by default are great for trimming memory overhead, what Java developers actually want comes down to day-to-day ergonomics: clean string interpolation without over-engineered templates, real language-level null safety with safecall operators instead of
Optionalclutter, and the long-promised flat memory layouts from Project Valhalla so our cloud bills stop getting crushed by stupid object overhead. Java has mastered runtime stability and throughput, but until writing routine application code stops feeling like an uphill battle against boilerplate compared to Kotlin or C#, everyday developer experience is going to lag behind.1
u/ohlaph Aug 23 '26
27! Man, I just updated my Android apps to 21, I guess I have some reading to catch up on.
1
u/simon_o Aug 23 '26
PEMDecoder.of()andPEMEncoder.of()look like a naming accident.1
u/EntertainmentIcy3029 Aug 24 '26
I mildly dislike the LLM writing style here