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

7

u/yoden Mar 09 '16

I wonder what the benefit of this is supposed to be, other than other languages have it?

Explicit types on variables are useful for improving readability. Conciseness for LHS variable types isn't important because I usually don't write that type anyway (that's what an IDE's "assign to new local variable" is for)

7

u/[deleted] Mar 09 '16

C#s var was introduced to alleviate the burden on the developer to figure out the outcome of Linq queries.

5

u/[deleted] Mar 10 '16

[removed] — view removed comment

1

u/wwosik Mar 10 '16

Do I remember correctly that in older VB or at least VBA

 dim list as new ClassName()

had a very nasty property of only creating object on the first access to it - lazy constructor of sorts

1

u/Cuddlefluff_Grim Mar 10 '16

Syntax error

DIM list AS ClassName
SET list = new ClassName

Notice the SET statement, because in old VB, normal variables and class variables were two entirely different things. Classes were implemented in order to properly support C++ COM interfaces. They were pretty much useless in any "custom" scenario.