@value标签引用另一个类

huangapple go评论67阅读模式
英文:

@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()

huangapple
  • 本文由 发表于 2023年6月1日 23:05:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定