Java 10 introduce the local variable declarator var, to be used instead of explicitly declaring a type with local variable. The type of the variable is then the upward projection of the variable initializer type.
- Java 9:
- Java 10:
See JLS10 - §14.4 - Local Variable Declaration Statements for details about semantic.
Note that according to JLS10 - §3.9, and is not part of the restricted keywords introduced for modules in Java 9:
- var is not a keyword, but rather an identifier with special meaning as the type of a local variable declaration.
As other local variable declarations, it means that it can be used as well in declaration of for and foreach statements (see JLS10 - §14.14), as well as in declaration of a resource in a try-with-resource statement (see JLS10 - §14.20.3)