
Java 9 中的 @Deprecated 注释 中添加了两个新参数或属性。这些参数是 Since 和 forRemoval,这两个参数当我们无法指定时,两个参数是可选的,带有默认值。
因为
此字符串参数指定API 已弃用的版本。此元素的默认值为空字符串。
语法
@Deprecated(since="")
forRemoval
此布尔值参数指定是否打算在未来版本中删除该 API。当我们无法指定时,默认值为false。
语法
@Deprecated(forRemoval=)
示例
public class DeprecatedAnnotationTest {
public static void main(String[] args) {
DeprecatedAnnotationTest test = new DeprecatedAnnotationTest();
test.method1();
test.method2();
}
@Deprecated(since="7.0")
public void method1() {
System.out.println("@Deprecated(since=\"7.0\")");
}
@Deprecated(since="5.0", forRemoval=true)
public void method2() {
System.out.println("@Deprecated(since=\"5.0\", forRemoval=true)");
}
}输出
@Deprecated(since="7.0") @Deprecated(since="5.0", forRemoval=true)











