Java如何将方法标记为已弃用?
要将方法标记为deprecated,我们可以使用JavaDoc@deprecated注解。这就是我们从Java开始以来所做的。但是当Java语言引入新的元数据支持时,我们也可以使用注释。将方法标记为deprecated的注注解是@deprecated。
这两者之间的区别在于,将@deprecated放置在JavaDoc注释块中,而将@Deprecated放置为源代码元素。
package org.nhooo.example.annotation;
import java.util.Date;
import java.util.Calendar;
public class DeprecatedExample {
public static void main(String[] args) {
DeprecatedExample de = new DeprecatedExample();
de.getDate();
de.getMonthFromDate();
}
/**
* Get current system date.
*
* @return current system date.
* @deprecated This method will removed in the near future.
*/
@Deprecated
public Date getDate() {
return new Date();
}
public int getMonthFromDate() {
return Calendar.getInstance().get(Calendar.MONTH);
}
}
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短