r/programming • • Mar 09 '16

var keyword proposed for Java

http://openjdk.java.net/jeps/286
250 Upvotes

395 comments sorted by

View all comments

Show parent comments

3

u/gbear605 Mar 10 '16

Just checked with Java keyword usability as variable names.

If I do

int int = 5;

it errors with

[javac] file.java:67: error: not a statement

[javac] 			int int = 5;

[javac] 			^

[javac] file.java:67: error: ';' expected

[javac] 			int int = 5;

[javac] 			   ^

[javac] file.java:67: error: not a statement

[javac] 			int int = 5;

[javac] 			    ^

[javac] file.java:67: error: ';' expected

[javac] 			int int = 5;

1

u/mike12489 Mar 11 '16

If it were a reserved keyword then it would certainly be a problem, but the proposal suggests incorporating "var"/"val"/etc as reserved type names (I.e., not keywords) specifically for backward-compatibility. This would only break pre-implementation packages using the types "var"/"val"/etc, which (as they mention) break Java conventions for type names anyway (Pascal case).

Although frankly primitives as keywords and "var" as just a reserved type doesn't seem quite fair..