Class RecordExamples
java.lang.Object
net.jrodolfo.java_evolution.java16.RecordExamples
Demonstrates records, finalized in Java 16.
Before records, simple immutable data carriers needed a lot of mechanical
code: fields, constructors, accessors, equals, hashCode, and
toString. That boilerplate obscured the actual data being modeled.
Records solve this by making the state declaration central. The compiler
generates a canonical constructor, accessors, equals,
hashCode, and toString from the record components.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordSimple record with generated accessors and value equality.static final recordRecord with a compact constructor for validation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a feature record.Uses a compact constructor to validate record data.
-
Constructor Details
-
RecordExamples
public RecordExamples()
-
-
Method Details
-
feature
Creates a feature record.- Parameters:
name- the feature nameversion- the Java version where it became final- Returns:
- a feature record
-
release
Uses a compact constructor to validate record data.- Parameters:
name- the language nameversion- the Java version- Returns:
- a validated release record
-