在以下的 MyMath
类中,我们定义了两个方法用于计算相加和相乘。为了方便其他开发者使用这个类,并且可以清晰地了解这个类的功能和方法使用方式,我们添加了 Javadoc 注释。
/**
* This is a simple math class to demonstrate Javadoc.
* It provides methods for addition and multiplication.
*
* @author Your Name
* @version 1.0
*/
public class MyMath {
/**
* This method adds two numbers.
*
* @param a The first number
* @param b The second number
* @return The sum of a and b
*/
public static int add(int a, int b) {
return a + b;
}
/**
* This method multiplies two numbers.
*
* @param a The first number
* @param b The second number
* @return The product of a and b
*/
public static int multiply(int a, int b) {
return a * b;
}
}
然后,我们在命令行中执行以下命令:
javadoc MyMath.java
这将会在当前目录下生成一个 doc
目录,里面包含了 MyMath
类的 API 文档。
接下来,我们就可以使用浏览器打开 doc/index.html
文件,来查看生成的 API 文档了。