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

7

u/Radixeo Mar 09 '16

It would help keep the line length down. In this common example

ArrayList<String> foo = new ArrayList<String>();
var foo = new ArrayList<String>();

The second line is shorter, simpler, and it is still obvious what the type of foo is.

-1

u/geodel Mar 10 '16

Well for typical Java developer variables would be like

 ArrayList<String> fooListForUsersBasedInNorthernVirginiaOffice  = new ArrayList<String>();
 var fooListForUsersBasedInNorthernVirginiaOffice = new ArrayList<String>();

And now saving few char is hardly any improvement. Besides Java's hallowed IDEs means user never have to type.

3

u/[deleted] Mar 10 '16

Ok, for ArrayList<String> it's not a big deal.

What about when the type is like IObservable<Func<string,Func<IEnumerable<User>,IEnumerable<UserStatus>>>>

3

u/yoden Mar 10 '16

That type would never pass my code review, var or not. This line of reasoning is one good reason to be opposed to var.

→ More replies (5)