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 给外婆敬酒祝福语简短