Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

java - @deprecated vs @Deprecated


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...