11

I would like to know the best way to add a comment to identify a deprecated class in Java. Should I remove the previous comment added to the top of the class that helps another programmer to know what was that class for, or should I add it below the comment?

17

The recommended approach to deprecating a class, method, or field in Java is to use the @Deprecated annotation, which became available in Java 5, or the @deprecated JavaDoc tag, which has been around since Java 1.1. Oracle has a document about the specifics on how and when to deprecate APIs that appears to be relevant.

Should i remove the previous comment added to the top of the class that helps another programmer to know what was that class for or add it below the comment?

You should not edit or remove any existing comments, other than to add the JavaDoc tag or annotation. Deprecated code might still be in use in legacy systems, and developers of those systems need to have access to the documentation that the original developers did in some form.

  • 1
    +1: Using the @Depricated annotations also give a heads up to IDEs like Eclipse to make sure to cross that method out and give other visual hints to developers. – Ryan Hayes Sep 5 '11 at 14:48
  • yes i know how to deprecate and the use off annotation my question is for example i have this code /** * comment about the class **/ public class ClassToDeprecate{ // some code here } should i remove the comment and be like this – alculete Sep 5 '11 at 14:49
  • 1
    @Spammer The article I linked to discusses that. Also, browsing through the Java API documentation answers that. The only thing that you should do is add the @Deprecated annotation or the @deprecated JavaDoc tag. That's it - nothing else, nothing more. – Thomas Owens Sep 5 '11 at 14:53
  • by the way, the link you gave was very helpfull – alculete Sep 13 '11 at 19:07
  • 1
    Adding @deprecated JavaDoc tag and description along with @Deprecated annotation will give more light into why it was deprecated. So it would be more beneficial to use both rather than just @Deprecated annotation. – WarFox Jul 8 '13 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.