As of JDK 14, we can replace our repetitious data classes with records. Records are immutable data classes that require only the type and name of fields.
The equals, hashCode, and toString methods, as well as the private, final fields, and public constructor, are generated by the Java compiler.
To create a Person record, we use the record keyword:
public record Person (String name, String address) {}
Java SE 14 (March 2020) introduced records as a preview feature.
Records aim to enhance the java language's ability to model "plain data" aggregates with less ceremony.
#JavaBeam #RecordsInJava14 #NewFeaturesInJDK14 #Java
Ещё видео!