Class RecordPreviewExamples
java.lang.Object
net.jrodolfo.java_evolution.java14.RecordPreviewExamples
Demonstrates records as a Java 14 preview feature.
Before records, simple immutable data carriers required constructors,
fields, accessors, equals, hashCode, and toString.
Most of that code was mechanical and easy to generate incorrectly.
Records solve this by letting the developer declare the data components and letting the compiler generate the standard value-based behavior. Records became final in Java 16. This project compiles on JDK 25, so this class uses final record syntax while documenting that Java 14 was the first preview release.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCompact data carrier used to demonstrate record syntax. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondescribe(RecordPreviewExamples.Feature feature) Formats a record using its generated accessor methods.Creates a record value.
-
Constructor Details
-
RecordPreviewExamples
public RecordPreviewExamples()
-
-
Method Details
-
feature
Creates a record value.- Parameters:
name- the feature namepreview- whether the feature was preview in Java 14- Returns:
- a record containing both values
-
describe
Formats a record using its generated accessor methods.- Parameters:
feature- the feature to describe- Returns:
- a readable description
-