Records

A record is a concise, immutable class declared with record, meant to carry data. The compiler generates the canonical constructor, the accessors (nom()), equals, hashCode, and toString. You can add a compact constructor to validate values, and methods.

Example

record Point(int x, int y) {}
var p = new Point(1, 2);
int x = p.x();

Related concepts

The whole glossary