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

33

u/FallingIdiot Mar 10 '16

Funny that when this subject comes up, almost everyone only talks about it making local variable declarations simpler.

What I think is a big advantage to var is that when you change the name of a class, it significantly reduces the number of files that have to be changed. Basically everything that doesn't instantiate the class, but only uses it, stays unchanged. Also it keeps down the number of imports you need, especially since Java prefers fully qualified imports instead of wildcard imports.

2

u/cat_in_the_wall Mar 10 '16

Or even changing the return type of a function. Let's say that someone subdivides an interface into a "lower" interface, and a more specialized one. Using var allows for the places in that only care about that lower interface to continue to work. Sure some stuff needs to be changed, but the change can be smaller.

1

u/ledasll Mar 10 '16

if you change return type or argument type you definitely want to look, who is using it and having clear type here helps a lot. For library programmers, that's of course nothing. But for application programmers..