What is a record, how does it differ from a normal class, and can it be a JPA entity?
Short answer
A record (since Java 16) is a class only for carrying data that doesn't change: declare the fields once and the compiler generates the rest.
3 points to say:
- It generates the constructor, getters,
equals,hashCode,toString. - Great as a DTO, not as a JPA entity.
- Only shallowly immutable: a list inside can still change.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.