Record in Java (A to X) || Java for All || SLDC PRO

Опубликовано: 07 Июль 2026
на канале: SDLC PRO
302
23

Covered in this lecture:
Record is a restricted form of a class. It’s ideal for "plain data carriers" with immutable manner and minimal code.

It is introduce as a preview feature in Java 14 and finalized in Java 16
How to declare a record?
Declare 1 get 5
Compiled version of a record
Fields of a record.
1. Private final field for each of it's components
2. Can't declare non-static fields
3. Possible to declare static fields

Methods of a record
1. Public read accessor method for each component with the same name and type of the component
2. Implementations of the equals(), hashCode() and toString() methods.

Constructures of a record
1. Public constructor whose signature is derived from the record components list. It is called canonical constructor.
2. We can define canonical constructor explicitly.
3. We can define compact constructor, it is a short version of canonical constructor.
4. We can define more constructure but that should deligate to canonical constructor explicitly.

Static and Non-static block
Record VS Inheritance
Record VS Class in serialization
Set[Record] VS Set[Class] (set of record vs set of class)