H.v.M.
H.v.M.

Reputation: 1659

What does the javadoc comment above package declaration do?

When I create a new class in Eclipse and check "Generate comments", I get this:

/**
 *
 */
package my_package;

/**
 * @author myname
 *
 */
public class MyClass {

}

What's the point of the comment above the package declaration? It doesn't seem to be included anywhere (if I put something there) when I generate javadocs. Is it just Eclipse misfiring, or a weird Eclipse setting I have, or is it there for a reason?

Upvotes: 4

Views: 894

Answers (2)

Ashish Patil
Ashish Patil

Reputation: 4624

For me, The comments generated above package are because of preference settings:

enter image description here

If I un-check Automatically add comments for new methods, types, modules ,packages and files, it is not appearing for me.

Moreover, if I edit Files comments, then File level comments are not appearing whenever I generate comments.

Upvotes: 1

Michael
Michael

Reputation: 44200

From Oracle

A doc comment is written in HTML and must precede a class, field, constructor or method declaration

There are also package-level comments which are placed in a file called package-info.java, which are used for generating documentation such as for the package java.time.

Trying to include a package-level comment in a regular source file seems like a bug. The docs state "you can place your comments in one of the following files...". IntelliJ also shows the warning "Dangling Javadoc comment" when package-level comments are placed in a regular source file.

Upvotes: 5

Related Questions