File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to mark a method deprecated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to mark a method deprecated" Watch "How to mark a method deprecated" New topic
Author

How to mark a method deprecated

Isuru Sampath
Ranch Hand

Joined: Jun 26, 2003
Posts: 57
How to deprecate a method in Java? If I place an @deprecated tag into the javadoc will it generate the compile time warnings on using a depricated method?


No Winds No Waves
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Why don't you try it yourself and see what the compiler says?

In Java 1.4 and older, you would use the @deprecated Javadoc tag for this:


In Java 5.0 and newer, you should use the @Deprecated annotation (although the old Javadoc tag will also still work):


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Isuru Sampath
Ranch Hand

Joined: Jun 26, 2003
Posts: 57
Thanks for the reply. Will try it out.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Jesper Young:
Why don't you try it yourself and see what the compiler says?

In Java 1.4 and older, you would use the @deprecated Javadoc tag for this:


In Java 5.0 and newer, you should use the @Deprecated annotation (although the old Javadoc tag will also still work):


FWIW, I recall reading somewhere a recommendation (that made sense - but I forget the detail of the reasoning - probably something to do with compiling to earlier targets) to use both the language annotation and the javadoc annotation for 1.5+


Tony Morris
Java Q&A (FAQ, Trivia)
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Originally posted by Tony Morris:
FWIW, I recall reading somewhere a recommendation (that made sense - but I forget the detail of the reasoning - probably something to do with compiling to earlier targets) to use both the language annotation and the javadoc annotation for 1.5+


Beyond that, does the @Deprecated annotation show up in Javadocs?
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Ken Blair:


Beyond that, does the @Deprecated annotation show up in Javadocs?


Yes it does. You will notice that the Deprecated annotation is annotated with the @Documented annotation. All such annotations appear in the javadoc.
 
Don't get me started about those stupid light bulbs.
 
subject: How to mark a method deprecated