【发布时间】:2011-02-03 06:15:52
【问题描述】:
我正在开发一个 API,其中包含许多名称相同的方法,只是签名不同,我想这很常见。它们都做同样的事情,除了如果用户不想指定,它们会默认初始化各种值。作为一个易于理解的例子,考虑
public interface Forest
{
public Tree addTree();
public Tree addTree(int amountOfLeaves);
public Tree addTree(int amountOfLeaves, Fruit fruitType);
public Tree addTree(int amountOfLeaves, int height);
public Tree addTree(int amountOfLeaves, Fruit fruitType, int height);
}
所有这些方法执行的基本操作是相同的;森林里种了一棵树。我的 API 用户需要了解的关于为所有这些方法添加树的许多重要事项。
理想情况下,我想编写一个可供所有方法使用的 Javadoc 块:
/**
* Plants a new tree in the forest. Please note that it may take
* up to 30 years for the tree to be fully grown.
*
* @param amountOfLeaves desired amount of leaves. Actual amount of
* leaves at maturity may differ by up to 10%.
* @param fruitType the desired type of fruit to be grown. No warranties
* are given with respect to flavour.
* @param height desired hight in centimeters. Actual hight may differ by
* up to 15%.
*/
在我的想象中,一个工具可以神奇地选择哪些@params 应用于每个方法,从而一次为所有方法生成好的文档。
对于 Javadoc,如果我理解正确的话,我所能做的基本上就是复制和粘贴同一个 javadoc 块五次,每个方法的参数列表略有不同。这对我来说听起来很麻烦,也很难维护。
有没有办法解决这个问题?有这种支持的 javadoc 的一些扩展?还是有充分的理由不支持我错过的?
【问题讨论】:
-
很好的问题和很好的描述,谢谢。