2.1) @Deprecated
@Deprecated 的定义如下:
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface Deprecated {
}
说明:
- (01) @interface -- 它的用来修饰 Deprecated,意味着 Deprecated 实现了 java.lang.annotation.Annotation 接口;即 Deprecated 就是一个注解。 (02) @Documented -- 它的作用是说明该注解能出现在 javadoc 中。
- (03) @Retention(RetentionPolicy.RUNTIME) -- 它的作用是指定 Deprecated 的策略是 RetentionPolicy.RUNTIME。这就意味着,编译器会将Deprecated 的信息保留在 .class 文件中,并且能被虚拟机读取。
- (04) @Deprecated 所标注内容,不再被建议使用。
例如,若某个方法被 @Deprecated 标注,则该方法不再被建议使用。如果有开发人员试图使用或重写被 @Deprecated 标示的方法,编译器会给相应的提示信息。示例如下:


本文详细介绍了Java中的@Deprecated注解,它用于标记已过时的元素,提示开发者不应再使用。@Deprecated是一个元注解,@Documented表明它会在API文档中显示,@Retention(RetentionPolicy.RUNTIME)意味着在运行时仍可获取该信息。当方法或类被@Deprecated标记,编译器会在尝试使用时给出警告。
https://www.bilibili.com/video/BV1qL411u7eE?spm_id_from=333.999.0.0
641

被折叠的 条评论
为什么被折叠?



