我正在开发一个 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 的某些扩展具有这种支持?或者是否有一个我错过的不支持的充分理由?