【问题标题】:Javadoc tag for performance considerations用于性能考虑的 Javadoc 标记
【发布时间】:2026-02-17 22:30:03
【问题描述】:
是否有考虑性能的 javadoc 标签?
可以想象:
/**
* ...other javadoc tags...
* @perform Expected to run in O(n) time if image exists with O(k) memory usage
*/
public Image getImage(URL url, String name) {
//code goes here
如果不是内置的,是否有一些人们使用的事实上的自定义标签?
【问题讨论】:
标签:
java
documentation
comments
javadoc
【解决方案1】:
从 Java 8 开始,为这种考虑添加了一个名为 @implNote 的新标签。
如here 所述,可以这样使用:
/**
* Picks the winners from the specified set of players.
* <p>
* The returned list defines the order of the winners, where the first
* prize goes to the player at position 0. The list will not be null but
* can be empty.
* @implNote This implementation has linear runtime and does not filter out
* null players.
* @param players
* the players from which the winners will be selected
* @return the (ordered) list of the players who won; the list will not
* contain duplicates
* @since 1.1
*/
default List<String> pickWinners(Set<String> players) {
return new ArrayList<>(players);
}
还添加了另外两个标签,在this 问题中进行了讨论。
值得注意的是,有一些细节表明这些不是 javadoc 规范的一部分,而是被 oracle 使用并在 JDK 中广泛使用的东西。因此,与上述相同的来源详细说明您必须使用以下命令行选项来启用它们:
-tag "apiNote:a:API Note:"
-tag "implSpec:a:Implementation Requirements:"
-tag "implNote:a:Implementation Note:"
它们在 IDE 中的支持量不同(例如,您不能在 Eclipse 中设置上述命令行参数),这使得它们的用处不如实际。
【解决方案2】:
真的没有标准。如果您要这样做,只需保持您(或您的组织)喜欢的格式并保持一致。