Moh*_*han 4 java javadoc default-value optional-parameters
我有一些 C++ 代码的 Java 包装器,在其中我通过手动重载相关方法来模拟默认参数。[示例如Java 是否支持默认参数值?.] 在一种情况下,C++ fn 有 3 个可选参数,因此我必须用 Java 编写 8 个方法。
现在我想为所述方法编写JavaDocs。有什么办法可以避免将基本相同的文本写 8 次吗?除了冗长之外,这将是一场维护噩梦......
编辑:这是一个玩具示例,说明了方法的签名:
void foo(int i, String s, double d);
void foo(int i, String s);
void foo(int i, double d);
void foo(int i);
void foo(String s, double d);
void foo(String s);
void foo(double d);
void foo();
Run Code Online (Sandbox Code Playgroud)
一种解决方案是在具有所有参数的方法中编写完整的 Javadoc 文档,然后使用和@link/或@see指令链接到重载中的该文档,例如:
/**
* The parameters in the wrapped C++ method are all optional,
* so we had to write an overload for each parameter combination.
* @param i the int parameter used for x.
* @param s the string parameter used for y.
* @param d the double parameter used for z.
*/
void foo(int i, String s, double d);
/**
* Overload of the {@link #foo(int, String, double)} method with a default {@code d}.
*/
void foo(int i, String s);
/**
* @see #foo(int, String, double)
*/
void foo(int i, double d);
...
Run Code Online (Sandbox Code Playgroud)