Java-Basic-6-文档注释

本文中主要说明文档注释。

注释类型

Java 本身包含三种注释

1
2
3
4
5
6
7
8
9
/**
文档注释,一般用在开头
*/

// 单行注释

/*
多行注释,似乎不太常用
*/

注意: 文档注释的结尾不是 */ ,而是 **/

Javadoc

Javadoc is a tool for generating API documentation in HTML format from doc comments in source code.

菜鸟的一个文档注释示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.*;

/**
* 这个类演示了文档注释
* @author Ayan Amhed
* @version 1.2
*/
public class SquareNum {
/**
* This method returns the square of num.
* This is a multiline description. You can use
* as many lines as you like.
* @param num The value to be squared.
* @return num squared.
*/
public double square(double num) {
return num * num;
}
/**
* This method inputs a number from the user.
* @return The value input as a double.
* @exception IOException On input error.
* @see IOException
*/
public double getNumber() throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader inData = new BufferedReader(isr);
String str;
str = inData.readLine();
return (new Double(str)).doubleValue();
}
/**
* This method demonstrates square().
* @param args Unused.
* @return Nothing.
* @exception IOException On input error.
* @see IOException
*/
public static void main(String args[]) throws IOException
{
SquareNum ob = new SquareNum();
double val;
System.out.println("Enter value to be squared: ");
val = ob.getNumber();
val = ob.square(val);
System.out.println("Squared value is " + val);
}
}

而后我们使用 javadoc 工具进行处理 javadoc <name>.java ,之后会生成包含程序注释的HTML文件。

一个详细的教程 小白都看得懂的Javadoc使用教程 - 说人话 - 博客园

如何在IDE中使用模板? 在 IDEA 上优雅地使用 Javadoc_javadoc 异常描述-CSDN博客

标签小全 Java 文档注释 | 菜鸟教程