Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

Your team owns a shared library and needs to remove a public method used by about 40 services. How do you use @Deprecated and related tooling to retire it safely?

Mark the method @Deprecated(since = "x.y", forRemoval = true) and add a Javadoc @deprecated tag that names the replacement, so every caller gets a removal warning that ordinary deprecation suppression cannot hide. Then find the callers, through build warnings and a search across the 40 repositories, track the migration, keep the method for at least the release cycle the consumers agreed to, and remove it only in a major version. To stop new uses during the transition, make builds fail on removal warnings.

Why this question is asked

Removing a method from a library that 40 services depend on is less about code and more about coordination. Delete it too early and 40 builds break on the next upgrade, often at the worst moment; never delete it and the library slowly fills with dead APIs nobody dares to touch. Interviewers ask this to see whether we know the tools Java gives us for deprecation and how we use them as part of a process. In this answer, we will mark the method properly, see what forRemoval changes in the compiler, find and track the callers, plan the release timeline, block new uses, and handle the teams who cannot upgrade in time.

1Marking the Method Properly

The first step is to tell every caller, in the place they will see it, that the method is going away and what to use instead. Two things do that together: the @Deprecated annotation, which the compiler acts on, and the Javadoc @deprecated tag, which explains it to humans in the IDE and the generated docs.

Java
/**
* Calculates the net price.
* @deprecated since 4.2, use {@link #net(Money, TaxRegion)} which handles regional tax.
* This method will be removed in 5.0.
*/
@Deprecated(since = "4.2", forRemoval = true)
public static Money netPrice(Money gross) {
return net(gross, TaxRegion.DEFAULT); // delegate, so both behave the same until removal
}

Notice that the old method delegates to the new one. That keeps a single implementation and means a caller who migrates sees no change in behaviour. The since attribute records when the deprecation started, which matters later when we decide whether enough time has passed.

2What forRemoval Changes

Plain @Deprecated means discouraged; many teams have hundreds of such warnings and have learned to ignore them, often with @SuppressWarnings("deprecation") on whole classes. forRemoval = true makes the compiler emit a removal warning instead, which is a separate category. Removal warnings are shown by default and are not hidden by suppressing deprecation; a caller has to write @SuppressWarnings("removal") deliberately to silence one.

Java
// In a consumer service
Money n = Prices.netPrice(gross);
// warning: [removal] netPrice(Money) in Prices has been deprecated and marked for removal
// @SuppressWarnings("deprecation") on the caller: the removal warning is still printed
// @SuppressWarnings("removal") on the caller: silenced, and clearly visible in code review

So forRemoval turns a soft hint into a visible, specific signal in every consumer build, without breaking anything yet.

3Finding and Tracking the Callers

Warnings only help if someone reads them, so we also find the callers ourselves. The compiler is our best detector: every consumer build that upgrades to 4.2 prints a removal warning at each call, and many CI systems can collect warnings into a report. For an inventory across all 40 repositories, a code search for the method name, or a bytecode scan of the deployed artifacts for references to Prices.netPrice, gives the full list, including services that have not upgraded yet. The JDK's jdeprscan tool scans class files for uses of deprecated APIs; it is aimed mainly at the JDK's own APIs, so check whether your version can report your library's methods before relying on it.

We then track the list like any migration: a ticket or a row per service, the owning team, and a status. If the library can record usage at run time, for example a counter or a rate-limited log line inside the deprecated method, production data tells us which services still call it, which catches code paths a search misses.

Step throughRetiring a public method
  1. Release 4.2: deprecateforRemoval = true, Javadoc names the replacement
  2. Find callersbuild warnings, code search, usage metric
  3. Track migration per serviceowner and status for each of 40
  4. Block new usesremoval warnings fail the build
  5. All callers migrated and agreed window passed?
    YesRemove in 5.0NoKeep it, follow up with the remaining teams

5 steps in order. Play them, or step through them one at a time.

4Planning the Timeline

The removal date should be a promise, not a surprise. We agree a deprecation policy with the consumer teams, for example that a deprecated method stays for at least one full minor release cycle, or at least six months, and is only removed in a major version. Under semantic versioning, removing a public method is a breaking change, so it belongs in 5.0, never in 4.3.

Announcing the timeline in the release notes, with a short migration guide and the exact replacement call, saves every consumer team from working it out themselves. For 40 services, an hour spent writing that guide saves days in total.

5Blocking New Uses During the Transition

The worst outcome is that while 30 teams migrate away, five others start using the method. We prevent that by making removal warnings fail the build. javac's -Werror turns all warnings into errors, which is too broad for most codebases, so teams usually combine it with a narrow -Xlint selection, or use a build check that fails only on removal warnings. Static analysis tools such as Error Prone or a Sonar quality gate can do the same per rule. Check your JDK and build tool for the exact options.

A shared parent POM or Gradle convention plugin is the natural place for this setting, so all 40 services get it with one change, and existing uses can be listed in a baseline file that shrinks as teams migrate.

6Follow-up questions

How do you handle consumers who cannot upgrade in time?

We give them a supported path rather than an exception to the rule. The 4.x line can stay on a maintenance branch for an agreed period, receiving only security and critical fixes, so a team can stay on 4.x while it schedules the migration. If many teams are stuck for the same reason, that is feedback that the replacement is missing something, and we fix the replacement or extend the window for everyone. What we avoid is keeping the method in 5.0 for one team, because then the removal never really happens.

Should the deprecated method log a warning at run time?

A rate-limited log line or, better, a metric can be useful to find callers in production that code search missed. It should never spam logs on every call or change behaviour, because the method must keep working exactly as before until it is removed.

Is deprecating without forRemoval ever the right choice?

Yes, when we want to steer people to a better API but have no plan to remove the old one, as the JDK did for many legacy methods. Using forRemoval only when removal is really planned keeps the signal meaningful.

7Conclusion

In this answer, we retired a public method used by 40 services in steps. We marked it @Deprecated(since, forRemoval = true) with a Javadoc @deprecated tag naming the replacement, and saw that forRemoval produces a removal warning that ordinary deprecation suppression cannot hide. We found callers through build warnings, code search and a usage metric, tracked the migration per service, kept the method for the agreed cycle and removed it only in a major version, blocked new uses by failing builds on removal warnings, and gave teams that could not upgrade a maintained older line.

What to say in the interviewAbout 90 seconds aloud

Open with

I would treat it as a migration with a timeline. In the next minor release I mark the method @Deprecated with since set to that version and forRemoval true, and add a Javadoc @deprecated tag that links to the replacement.

Then, if they want more

Ideally the old method just delegates to the new one, so behaviour stays identical. forRemoval matters because it produces a removal warning, which is a separate category from ordinary deprecation: it shows by default, and teams that suppress deprecation warnings broadly still see it unless they explicitly suppress removal.

Then I find the callers: the warnings in consumer builds, a code search or bytecode scan across all 40 repositories, and possibly a usage metric inside the method to catch production callers.

I track each service with an owner and status. jdeprscan exists, but it is mostly aimed at the JDK's own APIs, so I would not rely on it alone.

I keep the method for at least the release cycle we agreed with the consumers, announce the removal with a migration guide, and remove it only in the next major version, because removal is a breaking change. To stop new uses meanwhile, the shared build configuration fails on removal warnings.

For teams who cannot upgrade in time, the old major line stays on a maintenance branch for an agreed period.

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.
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 "Your team owns a shared library and needs to remove a public method used by about 40...": https://scrivio-interview-library.netlify.app/java/annotations/5df4ebfd4a/