Should I use /* */ or /** */ for the copyright in the top of a java file?
-
25-10-2019 - |
Question
There is a copyright comment in each java file, but I don't know which one should I use: /* */
or /** */
?
/*
* Copyright ...
*/
import java.util.*
...
or
/**
* Copyright ...
*/
import java.util.*
....
Solution
This rather old (circa 1999) Sun coding conventions document suggests /* */
.
More specifically, it suggests the following layout for your class/interface file(s):
Beginning comments
/* * Classname * Version information * Date * Copyright notice */
package
andimport
statements- Class and interface declarations (which includes Javadoc comments for the class - see table entry #1).
Example:
/*
* MyClass
*
* v1.0
*
* 2011-11-29
*
* This file is copyrighted in an awesome way.
*/
package com.example.mypackage;
import com.example.otherpackage;
/**
* Javadoc comments for the class.
*/
public class MyClass {
...
}
OTHER TIPS
Javadoc will only gather /** ... */
comments if they are directly before any declaration to be documented.
package
(other than in package-info.java) and import
declarations are not documented anyway, so Javadoc will not look at the comment in either way.
As it doesn't matter for Javadoc, you can as well use the "less heavy" /* ... */
version.
If you use /** */
documenting tools will grab it so you're better off using it :)
I just read some open source java projects, found they all use /* */