I'm able to deprecate a function or class with the @Deprecated
annotation.
But there is a @deprecated
javadoc tag in a javadoc comment itself marking the class/function as deprecated. Does the @deprecated
javadoc tag actually make the class/function deprecated?
The @Deprecated annotation tells the compiler that a method, class, or field is deprecated and that it should generate a warning if someone tries to use it.
As a general rule, if you're discussing the value of something or finances in general, the term to use will be “depreciate.” However, if you're referring to something being belittled – without necessarily impacting upon its perceived value – the correct word is “deprecate.”
"Obsolete" means "has been replaced". "Depreciated" means "has less value than its original value". "Deprecated" means to expressly disprove of and was popularised due to misspellings in two technical articles where the authors used deprecated without an "i".
Using the @Deprecated Annotation To use it, you simply precede the class, method, or member declaration with "@Deprecated." Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element.
@Deprecated
is an annotation that is read by the compiler, used to mark a method as deprecated to the compiler and will generate a deprecation compile-time warning if the method is used.
@deprecated
is a javadoc tag used to provide documentation about the deprecation. You can use it to explain why the method was deprecated and to suggest an alternative. It only makes sense to use this tag in conjunction to the @Deprecated annotation.
Example usage:
/**
* This method does ...
* @deprecated As of <product> <version>, because ... use
* {@link #replacementMethod()} instead.
*/
@Deprecated
public void deprecatedMethod() {
// ...
}
Here is a guide on deprecation, check it out for more information.
To answer your question more specifically, you should either use @Deprecated
or both. The @Deprecated
annotation marks your method as deprecated to any tool that cares about it, as it is available during both run-time and compile-time. The javadoc tool takes notice of @Deprecated
and documents the deprecation even if you didn't use the @deprecated
tag.
If we document a method as deprecated by using the javadoc tag, but without annotating it with the annotation, then the information about the deprecation will not be available in the compiled class files.
@deprecated Javadoc Tag: You can use the @deprecated tag to make Javadoc show a program element as deprecated. The @deprecated tag must be followed by a space or newline.
@Deprecated Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element. In contrast, there is no guarantee that all compilers will always issue warnings based on the @deprecated Javadoc tag
refer here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With