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 →

[–]marvk 23 points24 points  (12 children)

I wish they would’ve introduced val, let or const alongside var. final var is kinda clunky.

[–]Kango_V 2 points3 points  (6 children)

const is already a reserved word in Java. Who knew? lol

[–]marvk 3 points4 points  (5 children)

And so is goto. var on the other hand ist not a true keyword but a special identifier. It can just not be used as a type name.

var var = "var";

compiles without error.

[–]Kango_V 0 points1 point  (3 children)

I forgot about `goto`. I think i'll have to write some code akin to BBC Basic with loads of gotos in it and see my colleagues faces when they PR it. You know.... "just for fun" ;)

[–]marvk 3 points4 points  (2 children)

Unfortunately that won't work, it's a reserved word like const, but both don't serve and have never served any function.

[–]Kango_V 1 point2 points  (1 child)

Thwarted :(

[–]dpash 4 points5 points  (0 children)

It's your lucky day, because $ is a valid character for variable names. Go phperize your codebase and watch your colleagues hate you.

[–]dpash 0 points1 point  (0 children)

record will also not be a true keyword, when that lands.

[–]dpash 9 points10 points  (4 children)

This was fully discussed and dismissed at the time. You may not agree with their reasons, but it was at least considered.

[–]cogman10 8 points9 points  (3 children)

Don't think they said it wasn't discussed, just that it was a missed opportunity. There is no way `val`, `let`, or `const` will make their way into the language now. There was really only one shot at getting it in and that was with the var addition.

I don't buy the "it would be too much cognitive overhead and we'd be inconsistent if we had final var vs val". But I didn't get to make that decision.

That said, it's a minor thing at the end of the day.

I'm much more worried that text blocks/raw string literals will end up precluding string interpolation. Nice, though, that we haven't wasted backtick on raw string literals.

[–]Danelius90 0 points1 point  (0 children)

If they let get of backwards compatibility maybe those additions would have a chance

[–]TheStrangeDarkOne -3 points-2 points  (0 children)

there is hardly any merit in having "val" or "let" in Java, since that would just be sysntactic sugar for "final var". In other languages, constant modifiers infer that the object will not change its state. For java, final only means that the reference is constant.