I am trying to understand Java 10 Local Variable Type Inference. I seem to understand what it is, but I do not see any advantage from this. So I was wondering what is the idea behind introducing this feature. These are few of my observations. Please correct me if I am wrong here.
For example, (unlike other languages) I can not just declare a variable like this
var abc;I need to initialize it(But cannot initialize to null). So I don't really see any advantage whatsoever.
One of the other arguments I saw is that previously we had to declare a variable like this with its explicit types.
Map<User, String> userChannels = new HashMap<>();Now I can do it like this
var userChannels = new HashMap<User, String>();
With modern day IDE's(like IntelliJ IDEA) and their support for code completion. I cannot think of any added advantage that this brings to the table(in the above context).
Some of the other points I read were that
Polymorphic code doesn’t play nice with var.
And also I cannot use var for non denotable types like Anonymous class.
Given all these, why was it necessary to introduce this feature? Can someone please clarify If I am missing something here.