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

2

u/stun Mar 10 '16

It seems that Java developers don't really understand why it is very useful.
Regardless of how much the IDE can help with intellisense/type, having this var is an amazing feature that simplifies the code clutter.

1

u/Carighan Mar 11 '16

By requiring me to hover over variables to find out their type?

1

u/stun Mar 14 '16 edited Mar 14 '16

By the time you scroll down, you don't know what type it is anyway.
You mouse-hover it to see its type at that point regardless.

If you can see the variable declaration, there is no need to mouse-hover.

Consider the following declarations.
Which do you think is easier to read/scan?

var dictPeople = new Dictionary<int, People>();  
var listPeople = new List<People>();
var peopleListByDept = new Dictionary<int, List<People>>();

vs

Dictionary<int, People> dictPeople = new Dictionary<int, People>();  
List<People> listPeople = new List<People>();  
Dictionary<int, List<People>> peopleListByDept = new Dictionary<int, List<People>>();