Consider the following simplified interface inheritence hierarchy:
// Starting point:
public interface Base {
void Foo();
}
public interface Derived extends Base {
}
It is intended to move the Foo method from the Base interface to the Derived interface:
// Desired end-point:
public interface Base {
}
public interface Derived extends Base {
void Foo();
}
In order to phase in this breaking change, it is desired to retain backwards compatibility of the Base interface for some time.
This can be achieved by marking the method on the Base interface as @Deprecated:
// Intermediate state:
public interface Base {
/**
* @deprecated This method is deprecated as of release X. Derived.Foo should be used instead.
*/
@Deprecated void Foo();
}
public interface Derived extends Base {
void Foo();
}
When I compile this code I receive a compiler warning for Derived:
[deprecation] Foo() in interface Base has been deprecated
Oddly, if I remove the @deprecated from the documentation in Base (but leave the @Deprecated) this warning disappears.
Is it correct that I get this warning, and if so, how can I work around this?
The warning seems to communicate that Derived.Foo is "using" Base.Foo (which is deprecated). But the only capacity in which Derived.Foo is "using" the deprecated Base.Foo is to override it. That seems to say that you are not allowed to override deprecated interface methods in derived methods.
If this is the case, should I then decorate Derived with @SuppressWarnings("deprecation") to suppress the warning?