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 红包祝福语简短10字
18 周六早晨祝福语简短