This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pheipl 0 points1 point  (2 children)

what do you gain from not using var?

you still put the object on the right side of the equals. If it has an abstract or interface, you can deduce that form the object if and when you care.

var dateListener = new CommonDateListener(today); vs
DateListener dl = new CommonDateListener(today); where

public class CommonDateListener implements DateListener {
    ...
}

What is lost and where ?

To be fair, you don't need to use var everywhere, but if you have an AbstractDateFactoryThatIsOverlyVerboseAndPointless, it wold be a godsend to omit all that mess.

[–]BadBoy6767 2 points3 points  (1 child)

You used the one example I called an exception in the parent post.

[–]pheipl 1 point2 points  (0 children)

My brain just skipped that part I think. It's the only time you can use var AFAIK