• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to mark a method deprecated

 
Isuru Sampath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15445
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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):
 
Isuru Sampath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. Will try it out.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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+
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic