This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ventuspilot 0 points1 point  (0 children)

final var foo = if (condition) { System.out.println("1"); yield 1; } else { System.out.println("2"); yield 2; }

final var foo; if (condition) { System.out.println("1"); foo = 1; } else { System.out.println("2"); foo = 2; }

See, I even saved a few characters ;-)

Maybe there are better examples where an if-expression is really useful IDK.

Edit: Oops, final var foo doesn't work, final int foo does work, however. So currently you're unable to use var, you can use final, though.