Interview replay
Full round replay — records
Timed verbal replay with pass/fail criteria per follow-up.
How to run this
The opener
“When should you use a record instead of a class?”
Budget: 45 seconds. Going long here is itself a fail signal.
Follow-ups
1. “What can a record not do?”
Testing: Do they know the structural limits, not just the syntax?
Scoring
Pass: Extend a class — the superclass is always java.lang.Record. Be extended, since it is implicitly final. Declare instance fields beyond its components. And hold a mutable component safely.
Fail: 'Have methods' or 'implement interfaces' — both of which it can do.
2. “Is a record immutable?”
Testing: The single most common misconception.
Scoring
Pass: Shallowly. The fields are private final, which freezes the references. A mutable component makes it mutable in both directions — the caller keeps theirs, the accessor hands one out. List.copyOf in a compact constructor is the fix.
Fail: A flat 'yes'.
3. “Can you validate a record's components?”
Testing: Compact constructor, and whether they know it runs before assignment.
Scoring
Pass: Yes, in the compact constructor. It runs before the fields are assigned, so you can reject and also normalise by assigning to the parameter. Because it is the only way in, the invariant holds for every instance including deserialised ones.
Fail: 'No' or writes this.x = x inside a compact constructor.
4. “Does record equality behave like == for a double component?”
Testing: The sharpest separator here.
Scoring
Pass: No, and in both directions: NaN equals NaN in a record while NaN == NaN is false, and 0.0 does not equal -0.0 while 0.0 == -0.0 is true. Equals must be reflexive, so it uses Double.compare semantics.
Fail: 'Yes, it's just field comparison.'
5. “Would you use a record for a JPA entity?”
Testing: Value vs identity semantics.
Scoring
Pass: No. An entity has identity semantics — the same row is the same entity even when fields differ — and a record compares everything. Hibernate also needs a no-arg constructor and non-final fields. Records are the DTO you map the entity to.
Fail: 'Yes, it's less code.'
6. “When is a class still the right choice, other than for mutability?”
Testing: Judgement.
Scoring
Pass: Identity semantics, a field that must be excluded from equality, needing to extend or be extended, or when the component list is not something you want to publish — the names bind to every serialiser and to reflection.
Fail: 'Never, records are strictly better.'