Javadoc标记用于性能考虑

时间:2016-09-01 18:33:41

标签: java documentation comments javadoc

是否有用于性能考虑的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

如果没有内置,人们会使用一些事实上的自定义标签吗?

2 个答案:

答案 0 :(得分:1)

真的没有标准。如果你这样做,只需保持你(或你的组织)喜欢的格式并保持一致。

答案 1 :(得分: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中设置上述命令行参数),这使得它们没有那么有用。