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

74

u/evil_burrito Mar 09 '16 edited Mar 10 '16

I think one of the problems of untyped or weakly-typed languages is that they can be difficult to debug or understand somebody else's code.

I'm a fan of strong typing. I doubt that puts me in the majority here.

Edit: I'm simply stating a personal preference here: I think this will decrease the readability of source code. We don't all have to agree.

Edit: I can see how my original comment was poorly worded. I didn't mean to say, "I think this change will make Java less than a strongly-typed language", I meant to say, "I think this change might make Java read like less than a strongly-typed language".

4

u/kritzikratzi Mar 09 '16

you misread the article. java is, and always will be, strongly typed. this is about the compiler figuring out the for you.

// your source: 
var x = "hey"; 

// after the compiler does type inference: 
String x = "hey"; 

// this could also make generics a bit nicer
// java 6: 
HashMap<Integer,ArrayList<CustomThing>> myMap = new HashMap<Integer,ArrayList<CustomThing>>();

// java 7 with diamond: 
HashMap<Integer,ArrayList<CustomThing>> myMap = new HashMap<>(); 

// java ?? with var: 
var myMap = new HashMap<Integer,ArrayList<CustomThing>>(); 

to repeat: all of those are always strongly typed!

7

u/evil_burrito Mar 10 '16

No, I didn't misread it. My complaint isn't about the lexical structure of the language, my complaint is about ease of reading source code.