Java Arena

Module 56 Extra

Records

An extra module, not part of the MOOC. Records, Java's short way to write a class that only holds values (Java 16 and later). Declaring a record and reading its components, the equals, hashCode and toString Java writes for it, records as HashMap keys and in a HashSet, compact constructors that check or tidy the values, methods and static factories in a record, and when a class is the better choice.

Steps

  1. Declaring a record
  2. Records as keys
  3. Checking values with a compact constructor
  4. Methods and factories
  5. Class or record?