Understanding the record class
A record class simplifies the creation of a class that can only have immutable fields. Immutability means that the fields of a class are all final and must have a value assigned to them when the record
object is instantiated.
At its simplest, a record only needs the fields listed when the record
class is declared, as shown here:
public record Employee(String name, double salary) { }
When we instantiate this record, we must provide the values for name and salary:
var worker = new Employee("Bob", 43233.54);
All records have a default canonical constructor that expects a value for every field in the record. In a regular class, you would need to write a canonical constructor method to assign the values to the fields. You may add a compact constructor to a record that permits you to examine the value each field was assigned.
Here is a compact constructor. Notice that it does not have a parameter list, as it can only have a parameter...