如何在运行时获取方法的 JavaDoc? [英] How to get a JavaDoc of a method at run time?
本文介绍了如何在运行时获取方法的 JavaDoc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在运行时获取Class
的方法名
很容易
但是
如何在运行时获取方法的 JavaDoc
?
Its easy to get a method Name
of a Class
at run time
BUT
How i can get a JavaDoc
of a method at run time ?
如下例
包含目标方法的JavaDoc
的类
public class MyClass {
/**
*
* @param x value of ....
* @return result of ....
*/
public String myMethod(int x) {
return "any value";
}
}
我们的类有一个 main 方法
Our Class that has a main method
public class TestJava {
public static void main(String[] args) {
// get Class method Name at run time
String methodName = MyClass.class.getMethods()[0].getName();
System.out.println(methodName); // will print myMethod
// How to get a JavaDoc of myMethod `method` at run time
// MyClass.class.getMethods()[0].????
// expected to print a JavaDoc of myMethod
}
}
推荐答案
你不能:class
文件不包含注释.
You can't : the class
file doesn't contain the comments.
解决方案"是在构建程序时将 javadoc 生成为 HTML,并根据类名和方法名构建 URL.您还可以使用 doclet API.
A "solution" would be to generate the javadoc as HTML when you build your program and to build an URL from the name of the class and the name of the method. You could also generate the javadoc in a more suitable format than HTML using the doclet API.
这篇关于如何在运行时获取方法的 JavaDoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文