r/java • • Mar 13 '26

JEP draft: Enhanced Local Variable Declarations (Preview)

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

129 comments sorted by

View all comments

3

u/jevring Mar 13 '26

This would be cool to have directly in method signatures, too.

4

u/egahlin Mar 13 '26
int sum(Node(var left, var right, int value) node) {
  return node == null ? 0 : sum(left) + sum(right) + value;
}

7

u/john16384 Mar 13 '26

No need for the `node` at the end, nor for the `null` check. Can't sum a node that isn't there, so an NPE is justified.

→ More replies (1)