On this page
  1. var
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

var

Prev: `sealed` | Up: builtins | Next: `interface`
Rel: builtins, Classes, Records & Sealed Hierarchies
Ref: Java Docs — var
Tags: #public #prog #java #builtins #tier/core


Availability

Built-in / java.lang (Local Type Inference (Java 10+)) — available with zero import statements.

Syntax & Overview

var map = new HashMap<String, List<Integer>>();

Infers the static compile-time type of a local variable from its initializer (not dynamic typing).

Notes & Pitfalls

Example

var scores = java.util.Map.of("ada", 100, "bob", 90);
assert scores.get("ada") == 100;

Linked from

Related notes