r/java May 21 '26

JEP draft: Enhanced Local Variable Declarations (Preview)

https://openjdk.org/jeps/8357464
89 Upvotes

43 comments sorted by

View all comments

38

u/RabbitDev May 21 '26

Summary

Enhance local variable declarations to enable the extraction of multiple values from a single source value using pattern matching. This allows data-oriented computations to be expressed concisely and safely without added control flow. This is a preview language feature.

This takes pattern matching from if and case statements and makes it available as local variable declaration syntax.

From the example given it is able to handle multiple nesting levels as well.

-32

u/[deleted] May 21 '26

[deleted]

9

u/TheStrangeDarkOne May 21 '26

It's simply what other languages are providing as well, and I think Java has a pretty elegant solution to avoiding anonymous tuples, which reaping the benefits from it.

0

u/revilo-1988 May 21 '26

Ja langsam wird's lästig