Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

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.

share|improve this answer
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 –  Danilo 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
    
thanks Thomas and sorry for the late answer –  Danilo Sep 13 '11 at 18:51
    
by the way, the link you gave was very helpfull –  Danilo Sep 13 '11 at 19:07
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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