Jep323

1 post in this section

var Keyword (JEP 286, 323): Local Variable Type Inference

What var Does var is a reserved type name (not a keyword) introduced in Java 10 (JEP 286). It instructs the compiler to infer the type of a local variable from its initialiser. The inferred type is fixed at compile time — var does not make Java dynamically typed. // Before var ArrayList<String> names = new ArrayList<String>(); Map<String, List<Integer>> scores = new HashMap<String, List<Integer>>(); // With var var names = new ArrayList<String>(); var scores = new HashMap<String, List<Integer>>(); After compilation, both forms produce identical bytecode.

Continue reading »