Introducing Java Records (Preview)
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:
1
2
public record User(String name, int age) {}
It felt very Kotlin-esque. This small change has big ergonomic wins for DTO-heavy codebases.
This post is licensed under CC BY 4.0 by the author.