简体   繁体   中英

Difference between /* and /**

I found, in eclipse,

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

The comments will be green. However,

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

If I use /**, it will become blue. So why? Any difference?

While /* starts a regular multi-line comment, /** starts a multi-line comment supporting the javadoc tool , which generates HTML documentation from your comments.

This is an example from the documentation :

/**
 * 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;
    }
}

The Java API specification itself is an example of HTML documentation generated through javadoc .

Comments starting with /* are normal code comments. These are generally used on top of a code line to describe the logic.

Comments starting with /** are used for javadocs. These are used on top of methods and classes

/* is just a multiline comment.

/** is for Javadoc, which allow you to make a doc more readable for users.

Take a look

Javadoc

While the /** comment starter is for javadoc, technically they are actually the same from the compilers point of view. A comment is a comment is a comment. The important part here is that /** is /* with an extra asterisk added.

/* text */ : The compiler ignores everything from /* to */

/** documentation */ : This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation. For more information on javadoc, see the Java tool documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM