Annotation Interface Deprecated


@Documented@Retention(RUNTIME)@Target({CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PACKAGE,MODULE,PARAMETER,TYPE})public @interfaceDeprecated
A program element annotated@Deprecated is one that programmersare discouraged from using. An element may be deprecated for any of severalreasons, for example, its usage is likely to lead to errors; it maybe changed incompatibly or removed in a future version; it has beensuperseded by a newer, usually preferable alternative; or it is obsolete.

Compilers issue warnings when a deprecated program element is used oroverridden in non-deprecated code. Use of the@Deprecatedannotation on a local variable declaration or on a parameter declarationor a package declaration has no effect on the warnings issued by a compiler.

When a module is deprecated, the use of that module inrequires, but not inexports oropens clauses causesa warning to be issued. A module being deprecated doesnot causewarnings to be issued for uses of types within the module.

This annotation type has a string-valued elementsince. The valueof this element indicates the version in which the annotated program elementwas first deprecated.

This annotation type has a boolean-valued elementforRemoval.A value oftrue indicates intent to remove the annotated programelement in a future version. A value offalse indicates that use ofthe annotated program element is discouraged, but at the time the programelement was annotated, there was no specific intent to remove it.

API Note:
It is strongly recommended that the reason for deprecating a program elementbe explained in the documentation, using the@deprecatedjavadoc tag. The documentation should also suggest and link to arecommended replacement API, if applicable. A replacement API oftenhas subtly different semantics, so such issues should be discussed aswell.

It is recommended that asince value be provided with all newlyannotated program elements. Note thatsince cannot be mandatory,as there are many existing annotations that lack this element value.

There is no defined order among annotation elements. As a matter ofstyle, thesince element should be placed first.

The@Deprecated annotation should always be present ifthe@deprecated javadoc tag is present, and vice-versa.

SeeJava Language Specification:
9.6.4.6 @Deprecated
Since:
1.5
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Indicates whether the annotated element is subject to removal in afuture version.
    Returns the version in which the annotated element became deprecated.
  • Element Details

    • since

      String since
      Returns the version in which the annotated element became deprecated.The version string is in the same format and namespace as the value ofthe@since javadoc tag. The default value is the emptystring.
      Returns:
      the version string
      Since:
      9
      Default:
      ""
    • forRemoval

      boolean forRemoval
      Indicates whether the annotated element is subject to removal in afuture version. The default value isfalse.
      Returns:
      whether the element is subject to removal
      Since:
      9
      Default:
      false