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 姐妹结婚新婚祝福语简短