r/java • • Mar 09 '16

var keyword proposed for Java

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

312 comments sorted by

View all comments

43

u/solatic Mar 09 '16

Good idea. Hey, let's also introduce val as the equivalent of final var while we're at it, to promote immutability.

Why not?

13

u/shadowdude777 Mar 10 '16

I personally like taking it one step even further; I've seen that in Rust, immutable variables are declared as let foo = 1;, and mutables are declared as let mut foo = 1;.

I really like that. You have to add an extra word not to declare immutability, but to declare mutability. It really makes you think before you make anything mutable.

I also like var and val, like what Kotlin has, but I think that making someone add a whole extra word instead of just using a different word makes mutability seem more like an exception rather than the norm, as it should be.

7

u/navatwo Mar 10 '16

I think var and val come from scala originally. :) Still something to get behind.

3

u/shadowdude777 Mar 10 '16

Yeah, you're right. My mistake.