8.4 Records
Besides classes, interfaces, and enumeration types, another data type is available: records . [ 157 ] As with classes, objects can be created from records via new, but unlike classes, record objects are basically immutable, at least the direct fields of the record. In terms of syntax, little code is required to combine multiple data elements into a lightweight data structure; the specification refers to this code as nominal tuples .
8.4.1 Simple Records
The syntax in the declaration is also a little different from that of classes. First, the new record keyword is used , followed by the name of the data type, and then instead of the usual curly bracket, a parenthesis. The record components with their types and names follow ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access