如何通过代码检索Java注释?
我必须在标准输出上打印在 Java 类上写入的注释。我怎样才能这样做呢?
例如。
/**
* Comment to write
* @version 1.1
*/
public class WriteMyComment {
//something...
}
I must print on a standard output the comment write over a Java class. How can I do so?
eg.
/**
* Comment to write
* @version 1.1
*/
public class WriteMyComment {
//something...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我宁愿使用注释来完成您需要做的任何事情。我不确定是否可以在运行时访问源注释。
MyAnnotation.java
测试.java
I'd rather use annotations for whatever you need to do. I'm not sure is it possible to has access to source comments on runtime.
MyAnnotation.java
Test.java
我使用 QDox 来完成类似的任务,据我所知,我能够处理评论也。
I used QDox for a similiar task and as far as I remember, I was able to handle the comments too.
java 类文件中没有注释,因此如果没有源文件就无法使用它们。如果注释对您的应用程序有意义,请使用注释,它们是供应用程序使用的。
否则,您将不得不使用扫描源代码以获取注释的工具,例如 javadoc 或其他答案中提到的工具。
Comments are not available in the java class files, so you can't use them if you don't have the source files. If the comments mean anything for you application, use annotations, they are meant to be used by applications.
Otherwise you'll have to reside to tools that scan the source code for comments, perhaps like javadoc or tools mentioned in other answers.