IMO, var prevents a lot of needless changes if you, for example, decide you want to rename a class or change a method signature (move from returning Set to return Collection for example). It means less downstream changes and breaks and silly changes.
It also makes it much easier to write and use much more complex generics. Which is always a boon. It is no fun being at the wrong end of determining the generic type of a Map.of(Multimap.of(A.of(B, C)))
12
u/covercash2 Mar 09 '16
It seems safer than that in the article.
More like:
We all know what those will compile to. Anything else will have to be declared explicitly, though only once:
instead of
Although, I agree with the sentiment that a superclass should be used in a lot of cases, and that fudges with this var syntax a bit.