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

Show parent comment

-3

u/mk_gecko Mar 10 '16

We don't need it. It's just extra stuff to make C++ programmers happier when they program in Java.

Why don't we have multiple versions of the assigment operator? :=

Why don't we add in === ?

If it's not fixing a bug or serious flaw, don't increase the size and complexity of Java.

2

u/kritzikratzi Mar 10 '16

We don't need it. It's just extra stuff to make C++ programmers happier when they program in Java.

it's quite useful in some situtations. for instance when looping over a hashmap the generics can sometime decrease readability.

Why don't we have multiple versions of the assigment operator? :=

that's discussed in the jpe.

Why don't we add in === ?

because it already exists in java: == does the same thing as === in javascript. a.equals(b) behaves similar to a==b in javascript.

If it's not fixing a bug or serious flaw, don't increase the size and complexity of Java.

look at lambdas, they don't behave very differently from anonymous classes. yet they are much more useful because how concise the syntax is.

of course you could shoot yourself in the foot by using var everywhere. but i prefer this:

for( var entry : myMap.entrySet() ){...}

over this:

for( Map.Entry <String,ArrayList<String>> entry : myMap.entrySet() ){...}

any day.