我正在尝试使用@Deprecated注释.@Deprecated文档说:"编译器在未弃用的代码中使用或覆盖已弃用的程序元素时发出警告".我认为这应该触发它,但事实并非如此.javac版本1.7.0_09并使用而不是使用-Xlint和-deprecation进行编译.
public class TestAnnotations {
public static void main(String[] args)
{
TestAnnotations theApp = new TestAnnotations();
theApp.thisIsDeprecated();
}
@Deprecated
public void thisIsDeprecated()
{
System.out.println("doing it the old way");
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:根据下面的gd1的评论关于它只在该方法在另一个类中时才工作,我添加了第二个类.并且它在调用theOldWay()时会发出警告:
public class TestAnnotations {
public static void main(String[] args)
{
TestAnnotations theApp = new TestAnnotations();
theApp.thisIsDeprecated();
OtherClass thatClass = new OtherClass();
thatClass.theOldWay();
}
@Deprecated
public void thisIsDeprecated()
{
System.out.println("doing it the old way");
}
}
class OtherClass {
@Deprecated
void theOldWay()
{
System.out.println("gone out of style");
}
}
Run Code Online (Sandbox Code Playgroud)
警告:
/home/java/TestAnnotations.java:10:警告:[弃用]其他类中的OldWay()已被弃用
Run Code Online (Sandbox Code Playgroud)thatClass.theOldWay(); ^1警告
| 归档时间: |
|
| 查看次数: |
655 次 |
| 最近记录: |