I have some legacy code that implements a deprecated interface. This particular component will soon be deprecated and removed itself so it does not make sense to refactor to address the root cause of the compiler warning. Instead I'd like to suppress it. However, I do NOT want the scope of the suppression to be for the entire class.
The code was originally:
public class Foo
extends
Bar
implements
DeprecatedBaz,
Qux { ... }
DeprecatedBaz is an interface which has been marked as @Deprecated and is a third party framework meaning I am unable to remove the @Deprecated. I'd like to suppress the warning but not deprecations for the whole class. Essentially I'd like to write:
public class Foo
extends
Bar
implements
@SuppressWarnings("deprecation")
DeprecatedBaz,
Qux { ... }
However this is invalid syntax and does not parse. So next I had hoped I might be able to do it at the import but this SO post seems to imply it must be done at a class level.
Alternatively I thought potentially applying it to all of the methods that interface dictates must be implemented might address the issue but that did not work either.
So it seems I'm forced to apply the annotation at the class level:
@SuppressWarnings("deprecation")
public class Foo
extends
Bar
implements
DeprecatedBaz,
Qux { ... }
I don't like this because if someone edits this class and introduces new code which refers to deprecated code the warning will be swallowed.
Is there a way to limit the scope in this case?