Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@deprecated vs @Deprecated [duplicate]

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?

like image 784
N K Avatar asked Dec 19 '13 05:12

N K


People also ask

What does @deprecated annotation mean?

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.

Is it depreciated or deprecated?

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.”

Does deprecated mean obsolete?

"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".

Why is @deprecated used?

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.


2 Answers

@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.

like image 55
Ben Barkay Avatar answered Oct 19 '22 20:10

Ben Barkay


@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

like image 37
Nambi Avatar answered Oct 19 '22 19:10

Nambi