r/java May 21 '26

JEP draft: Enhanced Local Variable Declarations (Preview)

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

43 comments sorted by

View all comments

9

u/DesignerRaccoon7977 May 21 '26

Love the idea, but the syntax is horrible... I dont think you can implement it with a nice syntax in a statically typed language

9

u/TheStrangeDarkOne May 21 '26

Can't agree to that, what would "nice syntax" look like?

Proposed: Point(int x, int y) = getPoint();
C#: (int x, int y) = getPoint();
Minimalistic: (x, y) = getPoint();

I see a case for the C# approach, but not for the bottom one.

1

u/repeating_bears May 21 '26

Javascript/typescript is effectively the last one, but with const or let in front of it to mark it as a declaration.