Skip to main content
PreparationZone Logo
PrepZone

Local Variable Type Inference (`var`)

Where `var` helps readability, where it hurts, and why it is not dynamic typing.

Pass checkpoint below

Everyday use (Java 10+)

Java
public class Example {
    public static void main(String[] args) {
        var orders = new ArrayList<Order>();
            var entry = Map.entry("key", 1);
            for (var order : orders) {
                process(order);
            }
    }
}

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Test yourself

Answer these before moving on — recall is what makes it stick.