jdk/src/java.base/share/classes/java/lang/Deprecated.java
changeset 37304 c155b23ea178
parent 33520 b4fa17497a05
child 41553 eb5002231dfa
equal deleted inserted replaced
37011:c84d0cce090e 37304:c155b23ea178
    27 
    27 
    28 import java.lang.annotation.*;
    28 import java.lang.annotation.*;
    29 import static java.lang.annotation.ElementType.*;
    29 import static java.lang.annotation.ElementType.*;
    30 
    30 
    31 /**
    31 /**
    32  * A program element annotated @Deprecated is one that programmers
    32  * A program element annotated {@code @Deprecated} is one that programmers
    33  * are discouraged from using, typically because it is dangerous,
    33  * are discouraged from using. An element may be deprecated for any of several
    34  * or because a better alternative exists.  Compilers warn when a
    34  * reasons, for example, its usage is likely to lead to errors; it may
    35  * deprecated program element is used or overridden in non-deprecated code.
    35  * be changed incompatibly or removed in a future version; it has been
       
    36  * superseded by a newer, usually preferable alternative; or it is obsolete.
    36  *
    37  *
    37  * <p>Use of the &#64;Deprecated annotation on a local variable
    38  * <p>Compilers issue warnings when a deprecated program element is used or
    38  * declaration or on a parameter declaration or a package declaration
    39  * overridden in non-deprecated code. Use of the {@code @Deprecated}
    39  * has no effect on the warnings issued by a compiler.
    40  * annotation on a local variable declaration or on a parameter declaration
       
    41  * or a package declaration has no effect on the warnings issued by a compiler.
       
    42  *
       
    43  * <p>This annotation type has a string-valued element {@code since}. The value
       
    44  * of this element indicates the version in which the annotated program element
       
    45  * was first deprecated.
       
    46  *
       
    47  * <p>This annotation type has a boolean-valued element {@code forRemoval}.
       
    48  * A value of {@code true} indicates intent to remove the annotated program
       
    49  * element in a future version. A value of {@code false} indicates that use of
       
    50  * the annotated program element is discouraged, but at the time the program
       
    51  * element was annotated, there was no specific intent to remove it.
       
    52  *
       
    53  * @apiNote
       
    54  * It is strongly recommended that the reason for deprecating a program element
       
    55  * be explained in the documentation, using the {@code @deprecated}
       
    56  * javadoc tag. The documentation should also suggest and link to a
       
    57  * recommended replacement API, if applicable. A replacement API often
       
    58  * has subtly different semantics, so such issues should be discussed as
       
    59  * well.
       
    60  *
       
    61  * <p>It is recommended that a {@code since} value be provided with all newly
       
    62  * annotated program elements. Note that {@code since} cannot be mandatory,
       
    63  * as there are many existing annotations that lack this element value.
       
    64  *
       
    65  * <p>There is no defined order among annotation elements. As a matter of
       
    66  * style, the {@code since} element should be placed first.
       
    67  *
       
    68  * <p>The {@code @Deprecated} annotation should always be present if
       
    69  * the {@code @deprecated} javadoc tag is present, and vice-versa.
    40  *
    70  *
    41  * @author  Neal Gafter
    71  * @author  Neal Gafter
    42  * @since 1.5
    72  * @since 1.5
    43  * @jls 9.6.4.6 @Deprecated
    73  * @jls 9.6.4.6 @Deprecated
    44  */
    74  */
    45 @Documented
    75 @Documented
    46 @Retention(RetentionPolicy.RUNTIME)
    76 @Retention(RetentionPolicy.RUNTIME)
    47 @Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
    77 @Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
    48 public @interface Deprecated {
    78 public @interface Deprecated {
       
    79     /**
       
    80      * Returns the version in which the annotated element became deprecated.
       
    81      * The version string is in the same format and namespace as the value of
       
    82      * the {@code &#64;since} javadoc tag. The default value is the empty
       
    83      * string.
       
    84      *
       
    85      * @return the version string
       
    86      * @since 9
       
    87      */
       
    88     String since() default "";
       
    89 
       
    90     /**
       
    91      * Indicates whether the annotated element is subject to removal in a
       
    92      * future version. The default value is {@code false}.
       
    93      *
       
    94      * @return whether the element is subject to removal
       
    95      * @since 9
       
    96      */
       
    97     boolean forRemoval() default false;
    49 }
    98 }