0

如何从类中检索不推荐使用的方法列表。

我需要列出已标记为已弃用的方法,以便将类传递给文档。

我真的不想将每个方法及其 javadoc 复制并粘贴到单独的文件中,是否可以通过 javadoc 工具或通过 eclipse 来做到这一点?

4

2 回答 2

3

实际上 javadoc 会自动生成一个 deprecated-list.html 页面。只需运行 javadoc,看看是否是您需要的。

于 2009-03-10T10:17:11.373 回答
3

这将获取指定类的所有方法:

public class DumpMethods {
  public static void main(String args[])
  {
    try {
      Class c = Class.forName(args[0]);
      Method m[] = c.getDeclaredMethods();
      for (int i = 0; i < m.length; i++)
      System.out.println(m[i].toString());
    }
    catch (Throwable e) {
      System.err.println(e);
    }
  }
}

要获取已弃用的方法,对于每种方法,请执行以下操作:

Method method = ... //obtain method object
Annotation[] annotations = method.getDeclaredAnnotations();

for(Annotation annotation : annotations){
    if(annotation instanceof DeprecatedAnnotation){
        // It's deprecated.
    }
}
于 2009-03-10T10:23:55.257 回答