// Created on savesnippets.com · https://savesnippets.com/zo4QbeYjKeEqOe import java.util.*; class Demo { void example() { var name = "Alice"; // String var n = 42; // int var users = new HashMap>(); // no diamond noise // The right-hand side dictates the type — both are correct Map> longForm = new HashMap<>(); var shortForm = new HashMap>(); // In for-loops for (var entry : users.entrySet()) { // Map.Entry> System.out.println(entry.getKey() + " = " + entry.getValue()); } // ✗ var is ONLY for local variables — not for fields, params, returns // ✗ var without initializer is a compile error // ✗ var = null is a compile error (no type to infer) } }