var local type inference (Java 10+)
var infers the type at compile time from the initializer -- it is NOT dynamic typing, the variable's type
is fixed forever at that point, exactly as if you'd written it explicitly. It only works for local variables
with an initializer (never fields, parameters, or return types), and readability guidance generally says:
use it when the type is obvious from the right-hand side, skip it when the type carries real information the
reader would otherwise lose.
var list = new ArrayList<String>();
list.add("hi");
System.out.println("inferred type is fully static, still checked: " + list.getClass().getSimpleName());
var count = 42; // inferred as int
var label = "widgets"; // inferred as String
System.out.println(label + ": " + count);