OpenJDK Terminology

Records

July 03, 2026

Records, introduced as a preview in Java 14 and finalised in Java 16, are a concise way to declare classes whose primary purpose is to hold immutable data. Declaring record Point(int x, int y) {} gives you a class with a constructor, x() and y() accessor methods, equals(), hashCode(), and toString() — all generated automatically by the compiler.

Records are transparently immutable: the fields are final and can only be set via the constructor. You can add your own methods, implement interfaces, and define compact constructors (for validation), but you cannot add instance fields beyond those declared in the record header, and records cannot extend other classes.

Records pair naturally with sealed classes and pattern matching. Together, these features make it straightforward to model algebraic data types in Java — a style of programming sometimes called data-oriented programming.

Comments (0)

Your email address will not be published. Required fields are marked *

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

Save my name, email, and website in this browser for the next time I comment.

Comments (0)

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

No comments yet. Be the first.

Subscribe to foojay updates:

https://foojay.io/feed/
Copied to the clipboard