Quick revision
The short answer
Before approving, I would check five things: accessor names change from getX() to x(), which breaks callers and bean-based frameworks unless getters are kept; records are final and cannot extend a base class, which breaks subclasses; equals and hashCode change if the old classes compared only some fields; the Java serialization form changes and JSON can change too; and every one of these is a breaking change for consumers. So I would approve records for new types and internal DTOs, and convert public types only in a major version with automated compatibility checks.
What to remember
In this answer, we went through the compatibility issues of converting public library classes to records: accessor names change from getX() to x(), breaking source, binary and bean-based framework use unless getters are kept; records are final and cannot extend, breaking subclasses and base types; equality may change silently; and Java serialization and JSON forms can change. We detect breaks with japicmp or Revapi and snapshot tests, approve records for new and internal types, and convert public types only in a major version.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Before approving, I would check five things: accessor names change from getX() to x(), which breaks callers and bean-based frameworks unless getters are kept; records are final and cannot extend a base class, which breaks subclasses; equals and hashCode change if the old classes compared only some fields; the Java serialization form changes and JSON can change too; and every one of these is a breaking change for consumers. So I would approve records for new types and internal DTOs, and convert public types only in a major version with automated compatibility checks.
Why this question is asked
A shared library is a promise to every team that depends on it. Converting its public classes to records looks like a cleanup, but each class is used in ways the library team cannot see: called by name, subclassed, put in sets, serialized to disk, mapped by frameworks. Interviewers ask this question to see whether we can spot compatibility risks before they reach consumers and turn a team's enthusiasm into a safe plan. In this answer, we will go through each compatibility issue with an example, see how to detect them automatically, and finish with the approval decision.
1Source and Binary Compatibility in Two Sentences
Source compatibility means consumer code still compiles against the new library version. Binary compatibility means consumer code compiled against the old version still runs against the new one without recompiling, which matters because in a large organization many services pick up a new library version through a transitive dependency without anyone recompiling the code that uses it.
2Accessor Names Change
A typical library class has getters such as getAmount(). The record version has accessors named after the components, amount(). For consumers this is both a source break, their code no longer compiles, and a binary break, compiled code fails at run time with NoSuchMethodError when it calls the old method.
Frameworks are affected too. Anything that relies on JavaBeans getters, such as expression languages in templates, BeanUtils-style copying, older mapping libraries or reporting tools, may stop seeing the properties. The mitigation is to keep the old getters in the record, delegating to the accessors and marked @Deprecated, for at least one major version.
3Records Are Final and Cannot Extend
A record is implicitly final and already extends java.lang.Record. If any consumer subclassed the old class, for example to add a field or override toString for logging, that code no longer compiles. If the old class itself extended a library base class, say an AbstractResponse with common fields, the record cannot keep that relationship, and any consumer that accepts or casts to AbstractResponse breaks. We should search the organization's code for subclasses and for uses of the base type before deciding.
4Equality Semantics May Change
Record equality uses every component. Many hand-written classes defined equals over an identifier only, or excluded a timestamp. After conversion, two objects that used to be equal may no longer be, and the change is silent: the code compiles and runs, but sets now hold duplicates, cache lookups miss, and change detection fires constantly.
Silent behaviour changes are the most dangerous kind, because no build fails. For each class, compare the old equals with the record's all-components rule, and if they differ, either leave the class as it is or treat the change as a documented semantic break.
5Serialized Forms Change
Java serialization treats records differently from ordinary classes: it writes the component values and rebuilds the object through the canonical constructor. If consumers keep serialized objects anywhere, in caches such as a distributed session store, in message queues or in files, data written by the old version may not deserialize into the new record, and the reverse direction fails for consumers still on the old version during a rolling upgrade. Test both directions with real stored data before relying on it.
JSON may change as well. Jackson names record properties after the components, so a boolean getter isActive() that produced active may become isActive, and derived getters such as getDisplayName() on the old class may no longer be serialized if they are not components. Snapshot tests of the JSON for each converted type show these differences immediately.
- Do consumers call getX() or use bean frameworks?YesKeep deprecated gettersNoAccessor change is safe
- Is it subclassed, or does it extend a base class?YesDo not convertNoContinue
- Does the old equals use a subset of fields?YesDo not convert, or document a semantic breakNoContinue
- Is it serialized or sent as JSON?YesCompatibility tests in both directionsNoContinue
- Convert in the next major versionwith japicmp or Revapi reports in the build
5 steps in order. Play them, or step through them one at a time.
A conversion is approved only when every question has an answer.
6Detecting Breaks Automatically and Deciding
Manual review does not scale to hundreds of classes, so the build should compare the new library against the last released version. Tools such as japicmp and Revapi report removed methods, classes that became final and changed superclasses, and can fail the build on any binary incompatibility unless the version number signals a major release. JSON snapshot tests and serialization round-trip tests cover what those tools cannot see.
With that in place, my decision would be: yes to records for all new public types, since there is nothing to break, and yes to converting internal DTOs that are not exported. For existing public types, conversion happens only in a planned major version, with deprecated getters kept where consumers need them, equality differences documented or the class left alone, a migration guide, and the compatibility reports attached to the release. Converting hundreds of classes at once is not necessary for any business goal, so I would also ask the team to prioritise the types where records add real value, such as those used in pattern matching.
7Follow-up questions
Could we avoid the break by adding getters to every record?
Adding getX() methods that delegate to the accessors removes the method-name break, both source and binary. It does not fix finality, subclassing, equality or serialization differences, so it reduces the risk but does not make the change safe by itself.
Does semantic versioning solve the problem?
It tells consumers that something breaks; it does not tell them what. A major version is necessary, but consumers still need release notes listing the changed types, the behaviour differences and the migration steps.
What if only internal services use the library?
Then we can find every consumer and test them, which makes the change much cheaper. A monorepo or an organization-wide code search plus a coordinated upgrade can make a conversion practical that would be risky for a public library.
8Conclusion
In this answer, we went through the compatibility issues of converting public library classes to records: accessor names change from getX() to x(), breaking source, binary and bean-based framework use unless getters are kept; records are final and cannot extend, breaking subclasses and base types; equality may change silently; and Java serialization and JSON forms can change. We detect breaks with japicmp or Revapi and snapshot tests, approve records for new and internal types, and convert public types only in a major version.
Open with
Before approving I would go through compatibility one issue at a time. First, accessor names: the old classes have getAmount, the record has amount. That breaks consumer source, and it is a binary break too, compiled code gets NoSuchMethodError at run time, which matters because services pick up new library versions transitively without recompiling.
Then, if they want more
Frameworks that rely on JavaBeans getters can also stop seeing the properties, so I would keep the old getters as deprecated delegates if we convert. Second, records are final and cannot extend another class, so any consumer subclass breaks, and if the old class extended a base class, code that uses that base type breaks.
Third, equality: records compare all components, and if the old equals used only an id, behaviour changes silently, with duplicates in sets or missed cache hits. That one does not fail any build, so it worries me most.
Fourth, the serialized form: Java serialization handles records differently, so stored or cached objects may not read back across versions, and JSON names can change, for example isActive. To make this checkable, I would add japicmp or Revapi to the build against the last release, plus JSON snapshot and serialization round-trip tests.
My decision would be to approve records for new public types and internal DTOs right away, and to convert existing public types only in a planned major version, with the reports, a migration guide and deprecated getters where needed.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Teams want to convert hundreds of public API classes in a shared library to records....": https://scrivio-interview-library.netlify.app/java/records/21ba62d13a/