0
why var operation
2 Answers
+ 1
As we know that in JavaScript we declare variable with var keyword and var keyword automatically understand data type according to value.
So in latest version of Java we can also use var for any data type.
0
For my daily coding work the most important benefit of var is, that it makes refactorings a lot easier.
Renaming classes:
When you rename a class you do not have to touch every single class where a variable of that type exists, when it was just the value of a property or method coming from another class.
Changing return types:
When you change the return type of a method not every usage has to be touched when it does not execute specific operations on the result which cannot be supported anymore.
Besides the refactoring part, I personally like the readability it brings. When you declare multiple variables below each other all their names start at the same position.