Java / Java 21 Coding Standards Interview Questions
How do you troubleshoot deprecated API usage flagged by Java 21 standards tooling?
When the compiler or a linter flags @Deprecated usage, the first step is reading the annotation's own Javadoc and since/forRemoval attributes, since forRemoval = true signals the API will actually disappear in a future release, not merely fall out of favor.
@Deprecated(since = "9", forRemoval = true) public Date getDate() { ... } // -Xlint:deprecation on the build surfaces every call site with a warning
Compiling with -Xlint:deprecation lists every call site along with the file and line, which is the fastest way to get a complete inventory rather than discovering usages one at a time as the build happens to touch them.
Each flagged call site is then triaged: replace it with the documented replacement API where one exists (often named directly in the deprecation Javadoc), and where no direct replacement exists yet, isolate the deprecated call behind a small wrapper method so the eventual migration only has to change one place instead of every call site scattered across the codebase.
More Related questions...