0

Lets say we have below methods which is deprecated. If there is no use of this particular method. why don't we remove it or comment this line of code?

/**
 * Does some thing in old style.
 *
 * @deprecated use {@link #new()} instead.  
 */
@Deprecated
public void old() {
// ...
}
  • @SotiriosDelimanolis IMHO its not a duplicate since the part of what Deprecation is specified in the linked question but the difference between the commented out code and annotated is not explained. – Naman Sep 25 '17 at 16:02
  • 1
    @nullpointer _This means that the author wants to remove this method, but didn't do this yet to not break backward compatibility._ – Sotirios Delimanolis Sep 25 '17 at 16:03
  • Also @Deprecated annotation can be spotted by reflection for some reasons, for examle for logging (in the log file there will be a record that deprecated method is used) – agurylev Sep 25 '17 at 16:05
  • @nullpointer - So, How would compiler get to know which new latest code has to be used instead of that deprecated? Because when I run the code the compiler automatically gives a suggestion to use new code instead of deprecated one. –  Sep 26 '17 at 05:38
  • *compiler automatically gives a suggestion to use new code instead of deprecated one.* no that's not true unless the method marked @Deprecated has some implementation to share the intention. – Naman Sep 26 '17 at 05:41
  • 1
    @nullpointer Okei, got it.. Thanks –  Sep 26 '17 at 05:44

1 Answers1

0
  • Marking the implementation with comments altogether removes its implementation. All the existing code using the method old() would start breaking.

  • On the other hand, marking the code as @Deprecated serves a warning for such usages that a better alternative exists and the consumer should plan to move away from using this API before it is being cleaned up.

Naman
  • 27,789
  • 26
  • 218
  • 353