英文:
@value tag reference to another class
问题
我正在为我创建的一些实用方法生成一些javadoc注释。
如何使用@value
标签引用另一个类中定义的常量的实际值?
例如:
我的常量类
public class Constants {
public static final String SOME_CONSTANT = "theVal";
}
我的实用类
public class CoolUtil {
/**
*
* @return 基于{@value #Constants.SOME_CONSTANT}生成的MyObj
*/
public static MyObj generateIt(){
...
}
}
我希望javadoc的查看者看到Returns: a MyObj based on 'theVal'
我现在使用的语法似乎不起作用。如果我在CoolUtil
类内部定义常量,则@value
注解有效,但我不想创建常量的重复引用。
将不同的注释合并在一起以形成完整的句子可能会有所帮助。
英文:
I am generating some javadoc comments for a few utility methods that I created.
How can I use the @value
tag to reference the actual value of a constant that is defined in another class?
For example:
My constants class
public class Constants {
public static final String SOME_CONSTANT = "theVal";
}
My utility class
public class CoolUtil {
/**
*
* @return a MyObj based on {@value #Constants.SOME_CONSTANT}
*/
public static MyObj generateIt(){
...
}
}
I want the viewer of the javadoc to see Returns: a MyObj based on 'theVal'
The syntax that I'm using now doesn't seem to work. If I have the constant defined inside the CoolUtil
class, the @value
annotation works, but I don't want to have to create a duplicate reference to the constant.
Any help/tips would be appreciated.
答案1
得分: 1
根据文档 https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#link
当在任何文档注释中与参数 package.class#field 一起使用时,它会显示指定常量的值。
在你的情况下:
/**
*
* @return 基于 {@value com.yourpackage.Constants#SOME_CONSTANT} 的 MyObj
*/
public static MyObj generateIt()
英文:
According to the doc https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#link
> When used with argument package.class#field in any doc comment, it displays the value of the specified constant
In your case:
/**
*
* @return a MyObj based on {@value com.yourpackage.Constants#SOME_CONSTANT}
*/
public static MyObj generateIt()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论