JavaBeginner#fundamentals#java10

What is the difference between var and explicit typing in Java 10+?

var lets the compiler infer the local variable's type from the initializer at compile time; it's still statically typed, not dynamic. It can only be used for local variables with an initializer, not fields or method parameters.

Example
var list = new ArrayList<String>(); // inferred as ArrayList<String>
list.add("hi");
// var x; // error: no initializer to infer from

Related Questions

1
JavaIntermediate#inner-classes

What is the difference between a static nested class and a non-static inner class?

Open
2
JavaIntermediate#inner-classes

What are anonymous inner classes used for?

Open
3
JavaIntermediate#inner-classes

What is a local class in Java?

Open