1、javadoc 为何物?
** 大致来讲是为了让其他人快速了解本这个文件 及文件中方法的参数调用情况、返回值类型的“清单”
2、javadoc 生成方法
step1: 在文件内写描述整个文件的注释
/**
* Title: Cat.java Description: This class contains the definition of a cat
*
* @author wang
* @version 1.1
*
*/
Note: 第一行/ 后面一定是两个星号
step2: 在文件内写方法的
/**
*
* @param duration
* @param zigzag
* @return int
*/
Note: 在eclipse中,写完/** 后面大部分内容都会自动生成 return后面没有,自行补充返回值类型即可,最后再 变量/类型后面加一些描述
step3: 生成javadoc
方法一:使用终端:(以macOS 为例)
打开终端 添加路径 cd + 空格+(把文件夹拖进来)
javadoc -d (给javadoc起的名字) 文件名.java
如 :
javadoc -d hello Cat.java
方法二:在eclipse 中生成:
案例:
import java.awt.Color;
/**
* Title: Cat.java Description: This class contains the definition of a cat
*
* @author wang
* @version 1.1
*
*/
public class Cat
{
private String name, furType;
private boolean tail;
private Color colour;
private int speed;
/**
*
* @return String
*/
public String getName()
{
return name;
}
/**
*
* @param name
*/
public void setName(String name)
{
this.name = name;
}
/**
*
* @return String
*/
public String getFurType()
{
return furType;
}
/**
*
* @param furType
*/
public void setFurType(String furType)
{
this.furType = furType;
}
/**
*
* @return boolean
*/
public boolean isTail()
{
return tail;
}
/**
*
* @param tail
*/
public void setTail(boolean tail)
{
this.tail = tail;
}
/**
*
* @return Color
*/
public Color getColour()
{
return colour;
}
/**
*
* @param colour
*/
public void setColour(Color colour)
{
this.colour = colour;
}
/**
*
* @return int
*/
public int getSpeed()
{
return speed;
}
/**
*
* @param speed
*/
public void setSpeed(int speed)
{
this.speed = speed;
}
/**
*
* @param name
* @param furType
* @param tail
* @param colour
* @param speed
*/
public Cat(String name, String furType, boolean tail, Color colour, int speed)
{
this.name = name;
this.tail = tail;
this.colour = colour;
this.speed = speed;
}
/**
* Description : this is a sleep method of cat
*
* @param duration the number of minutes to sleep.
*/
public void sleep(int duration)
{
System.out.println("I am sleep for" + duration + " minutes");
}
/**
*
* @param duration
* @param zigzag
* @return int
*/
public int run(int duration, boolean zigzag)
{
System.out.println("i am running" + (zigzag ? " in zigzag" : "straight") + " for " + duration + " minutes");
int distanceRun = duration * speed;
if (zigzag)
{
return distanceRun = distanceRun / 3;
} else
return distanceRun;
}
}