/* 和 /** 之间的区别

2022-09-03 14:03:21

我发现,在日食中,

/*
 * Hello world, this is green.
 *
 */

注释将为绿色。然而

/**
 * Hello moon, this is blue.
 *
 */

如果我使用 /**,它将变为蓝色。这是为什么呢?有什么区别吗?


答案 1

在启动常规多行注释时,启动支持 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 规范本身就是通过 生成的 HTML 文档的一个示例。javadoc


答案 2

以 开头的注释是正常的代码注释。这些通常用于代码行的顶部来描述逻辑。/*

以 开头的注释用于 javadocs。这些用于方法和类之上/**


推荐