Records
17 questions in 6 subtopics.
Record semantics
What does the compiler generate forrecord Point(int x, int y) {}, and what restrictions do records have?How are record equals, hashCode and toString implemented at the bytecode level, and what reflection support do records have?Records were described as data carriers with transparent state rather than as a way to reduce boilerplate. Why does that distinction matter, and how should it guide where records are allowed in an organization's architecture?Compact canonical constructors
Write a recordRange(int lo, int hi) that rejects lo > hi, using a compact canonical constructor, and explain how it differs from a full canonical constructor.A record Email(String value) is used across a codebase. Where should normalisation (lowercase, trim) and validation go, and how do you avoid creating invalid instances through deserialization?A records-heavy event model has validation in compact constructors that calls external services and reads configuration. Events fail to deserialize during an outage. What design change do you make?Records and immutability
A recordTeam(String name, List<String> members) is used as a map key. After a caller modifies the list, the map lookup fails. Why, and how do you fix it?Are records immutable? Compare them with a hand-written immutable class and with Lombok @Value.Records, unmodifiable collections and value-based classes show a long trend in Java towards immutable data. How would you steer an organization whose codebase relies on mutable beans and setters towards immutable data over several years?Records with Jackson and JPA
After switching a DTO from a class to a record, Jackson output changes field names for a component calledisActive, and a client breaks. Explain what to check.A team wants to use records for request and response DTOs in Spring MVC with Jackson, and also as JPA entities. What works and what does not?Your platform team wants a standard for API DTOs across fifty Spring Boot services, choosing between records, Lombok classes and hand-written classes. What do you decide and how do you roll it out?Local records
Use a local record to sort orders by total value computed from line items, without adding a new top-level class.Why are local records implicitly static, unlike local classes, and what does that mean for what they can reference?When not to use records
List cases where you should not use a record, and explain why for each.Teams want to convert hundreds of public API classes in a shared library to records. What compatibility issues do you consider before approving?Records were deliberately limited: no extension, no extra instance fields and accessors that expose all state. Explain why the designers accepted these limits rather than building a general boilerplate reducer, and how this should shape your organization's guidance.No question matches these choices.