liveBook · Manning

Java record

As explained in Troubleshooting Java, Second Edition

A Java record is a Java class-like language feature for declaring data-oriented types with implicitly final components and generated data-access methods.

A Java record is a class-like language feature for data-oriented types whose components are implicitly final. Records strengthen immutability in a model layer, but their values cannot be changed on the fly during debugging. section 3.3

Use records with these investigation rules:

  • Expect the IDE to reject attempts to modify a record component while execution is paused. section 3.3
  • If changing in-memory values is central to testing a hypothesis, inspect the data with breakpoints but use another approach for immutable values. section 3.3

Debugging an immutable model

A paused debugger can change an ordinary variable to create a new investigation case, such as replacing input with "abcd". It cannot similarly modify a record component because that component is final. section 3.3

How Troubleshooting Java, Second Edition covers it

How deep it goes
Defines implicit final components and the resulting debugger limitation, but does not detail record syntax or generated methods.
Examples
Uses paused-debugger variable changes and an "abcd" input to contrast mutable investigation cases with immutable record components.
What you can do after
Diagnose debugging constraints by recognizing when record immutability prevents changing investigation data in the IDE.
How it connects
Connects immutability, final variables, model layers, breakpoints, and debugging investigations.

Also explained in

Compare how 4 books explain Java record →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.