Actually the behaviour seeems the right one for me: when you override a method is a symbol you implement a new code for it.
To avoid errors, if you use a deprecated super method, eclipse will raise a warning:
class Sub extends Super{
@Override
public void doNotUseThisMethod() { // <---------------*
super.doNotUseThisMethod(); // deprecated! <----*
}
}
But if you override a deprecated method functionallity without using the deprecated super.method()
then new method is not deprecated by definition, because you implemented it without using the old one.
public class Sub extends Super{
@Override
public void doNotUseThisMethod() {
// new logic + not using super.method() = not a deprecated method!!
}
}
If the one that overrides the deprecated one, shouldn't be used, must be also annotated as deprecated as follows:
public class Super {
@Deprecated
public void doNotUseThisMethod() {
// do magic
}
}
public class Sub extends Super{
@Override
@Deprecated // <---------------------------*
public void doNotUseThisMethod() { // |
// this is deprecated also!!!! // <-----*
}
}
SIDENOTE: Another question will be if the name of your method can cause confusion.
But doesn't @Deprecate also mean "we're going to delete this method soon", which will break the code of the subclass thanks to the @Override annotation? (That's exactly why I need the warning - to prevent other developers from overriding a method I'm going to delete. But as it is they won't even get a warning.) – Steffi S.
Actually It could happen developers delete the method, but deprecation is more about not using the code in some method because is old, then developers make a NEW one, with NEW name and leave deprecated one as legacy.
But... What would happen in the case this method is deleted?
First of all, this would mean a change of Java (or framework, or utils) version, this should be done carefully, deprecated methods won't be your only problem.
In the case you choose major version and some deprecated methods are deleted, you won't have much problem... Why? Your IDE will clearly mark this methods with an error, and you just need to delete the @Override
annotation, having your logic safe in your overriden method.