我在eclipse中发现了
/*
* Hello world, this is green.
*
*/
评论将会是绿色的。但是,
/**
* Hello moon, this is blue.
*
*/
如果我使用/**,它会变成蓝色。
那为什么?有什么不同吗?虽然/*
可以开始多行注释,但是/**
可以用于开始支持javadoc
工具的多行注释,该工具可以从您的注释生成HTML文档。
以下是来自文档中的示例:
/**
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute {@link URL}. The name
* argument is a specifier that is relative to the url argument.
* <p>
* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded. The graphics primitives
* that draw the image will incrementally paint on the screen.
*
* @param url an absolute URL giving the base location of the image
* @param name the location of the image, relative to the url argument
* @return the image at the specified URL
* @see Image
*/
public Image getImage(URL url, String name) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
Java API 规范本身 是通过 javadoc
生成的 HTML 文档的一个示例。
以/*
开头的注释是普通的代码注释。这些注释通常用于代码行顶部,用于描述逻辑。
以/**
开头的注释用于Javadoc。它们用于方法和类的顶部。
虽然 /**
注释起始符是用于 javadoc 的,但从编译器的角度来看,它们实际上是相同的。注释就是注释。重要的是,这里的关键部分是 /**
是在 /*
后面加了一个额外的星号。
/* 文本 */
: 编译器会忽略从/*
到*/
之间的所有内容
/** 文档 */
:
这表示一个文档注释(简称doc注释)。编译器会像忽略使用/*和*/的注释一样忽略这种类型的注释。JDK javadoc工具在准备自动生成的文档时使用doc注释。有关javadoc的更多信息,请参见Java工具documentation