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

11

u/TheNiXXeD Mar 09 '16

Final already exists. It's not about immutability, but you can't reassign that reference.

16

u/rabidcow Mar 09 '16

It is about immutability, but shallow immutability. Since primitives are the only values types, that means just the reference for anything else.

2

u/id2bi Mar 10 '16

Or say that we are talking about the (im)mutability of variables, not values.

I'm not sure talking about "shallow immutability" is appropriate in this context. When you do a shallow copy, only the fields will be copied (i.e. copies of primitives, and copies of references), so this suggests that shallow immutability means the fields will also not be re-assignable.

This is also backed up by this:

https://homes.cs.washington.edu/~mernst/pubs/immutability-aliasing-2013-lncs7850.pdf

-1

u/[deleted] Mar 09 '16

Which kind of sucks and is a good reason not to use the "val" keyword.