目录
- 一 笔记
- 二 Deprecated 源码
- 三 定义一个已过时的类 AnnotationTest03_User.java
- 四 使用自定义的过时注解类
一 笔记
@Deprecated 可以标注很多元素:类、接口、方法、属性。。。。。。
- 这个注解也是给编译器看的,也是做编译检查的;
- 被这个注解标注的元素表示已过时,在编译器进行编译的时候会进行“过时提醒”;
二 Deprecated 源码
/** Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.*/package java.lang;import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;/*** A program element annotated @Deprecated is one that programmers* are discouraged from using, typically because it is dangerous,* or because a better alternative exists. Compilers warn when a* deprecated program element is used or overridden in non-deprecated code.** @author Neal Gafter* @since 1.5* @jls 9.6.3.6 @Deprecated*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
public @interface Deprecated {
}
三 定义一个已过时的类 AnnotationTest03_User.java
把一个类定义为已过时的注解;@Deprecated
@Deprecated 被这个注解标注的元素表示已过时,在编译器进行编译的时候会进行“过时提醒”;
@Deprecated
public class AnnotationTest03_User {@Deprecatedpublic AnnotationTest03_User(){System.out.println("我是AnnotationTest03_User(),是一个被@Deprecated修饰的类,已经过时。");}
}
四 使用自定义的过时注解类



















