Path: blob/master/src/java.base/share/classes/java/lang/Deprecated.java
41152 views
/*1* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang;2627import java.lang.annotation.*;28import static java.lang.annotation.ElementType.*;2930/**31* A program element annotated {@code @Deprecated} is one that programmers32* are discouraged from using. An element may be deprecated for any of several33* reasons, for example, its usage is likely to lead to errors; it may34* be changed incompatibly or removed in a future version; it has been35* superseded by a newer, usually preferable alternative; or it is obsolete.36*37* <p>Compilers issue warnings when a deprecated program element is used or38* overridden in non-deprecated code. Use of the {@code @Deprecated}39* annotation on a local variable declaration or on a parameter declaration40* or a package declaration has no effect on the warnings issued by a compiler.41*42* <p>When a module is deprecated, the use of that module in {@code43* requires}, but not in {@code exports} or {@code opens} clauses causes44* a warning to be issued. A module being deprecated does <em>not</em> cause45* warnings to be issued for uses of types within the module.46*47* <p>This annotation type has a string-valued element {@code since}. The value48* of this element indicates the version in which the annotated program element49* was first deprecated.50*51* <p>This annotation type has a boolean-valued element {@code forRemoval}.52* A value of {@code true} indicates intent to remove the annotated program53* element in a future version. A value of {@code false} indicates that use of54* the annotated program element is discouraged, but at the time the program55* element was annotated, there was no specific intent to remove it.56*57* @apiNote58* It is strongly recommended that the reason for deprecating a program element59* be explained in the documentation, using the {@code @deprecated}60* javadoc tag. The documentation should also suggest and link to a61* recommended replacement API, if applicable. A replacement API often62* has subtly different semantics, so such issues should be discussed as63* well.64*65* <p>It is recommended that a {@code since} value be provided with all newly66* annotated program elements. Note that {@code since} cannot be mandatory,67* as there are many existing annotations that lack this element value.68*69* <p>There is no defined order among annotation elements. As a matter of70* style, the {@code since} element should be placed first.71*72* <p>The {@code @Deprecated} annotation should always be present if73* the {@code @deprecated} javadoc tag is present, and vice-versa.74*75* @author Neal Gafter76* @since 1.577* @jls 9.6.4.6 @Deprecated78*/79@Documented80@Retention(RetentionPolicy.RUNTIME)81@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, MODULE, PARAMETER, TYPE})82public @interface Deprecated {83/**84* Returns the version in which the annotated element became deprecated.85* The version string is in the same format and namespace as the value of86* the {@code @since} javadoc tag. The default value is the empty87* string.88*89* @return the version string90* @since 991*/92String since() default "";9394/**95* Indicates whether the annotated element is subject to removal in a96* future version. The default value is {@code false}.97*98* @return whether the element is subject to removal99* @since 9100*/101boolean forRemoval() default false;102}103104105