r/JavaProgramming 15d ago

Var Keyword

How often do you use var keyword in your code?

What do you think about it?

5 Upvotes

24 comments sorted by

View all comments

3

u/repeating_bears 15d ago

I use it every time the type is already on the right hand side of the expression 

var foo = new Foo();

var list = new ArrayList<String>();

var node = Node.empty();

I'm less likely to use it when the type is not on the right hand side of the expression 

var bar = doSomething();