Introducing Java Records (Preview)
Introducing Java Records (Preview)

Introducing Java Records (Preview)

Author
Shiv Bade
Tags
java 14
records
Published
April 24, 2019
Featured
Slug
Tweet
Java Records were introduced as a preview feature in JDK 14, but discussions began way earlier.
Why they're exciting: - Reduce boilerplate for immutable data classes - Automatically generate equals, hashCode, toString - Enforce canonical constructor
Example:
public record User(String name, int age) {}
It felt very Kotlin-esque. This small change has big ergonomic wins for DTO-heavy codebases.