What is the difference between / * ... * / and / ** ... * /

I noticed that Eclipse prints different comment formats:

/* Eclipse prints it in green */ 

or if you write:

 /** Eclipse prints it in blue */ 

What is the difference between these two comments?

+5
source share
3 answers
 /* * It is multi-line comment in Java * */ /** * It is a Javadoc. Can be found above methods and Class definitions. * * */ 

Here is an excerpt from Wikipedia regarding Javadoc:

Javadoc comments are entered from the code using the standard multi-line comment tags / * and * /. The opening tag (called the start-comment separator) has an extra asterisk, as in / **.

 The first paragraph is a description of the method documented. Following the description are a varying number of descriptive tags, signifying: The parameters of the method (@param) What the method returns (@return) Any exceptions the method may throw (@throws) Other less-common tags such as @see (a "see also" tag) 

Javadoc class level Example:

 /** * @author Firstname Lastname <address @ example.com> * @version 1.6 (current version number of program) * @since 2010-03-31 (the version of the package this class was first added to) */ public class Test { // class body } 

Javadoc Method Level Example:

 /** * Short one line description. * <p> * Longer description. If there were any, it would be * here. * <p> * And even more explanations to follow in consecutive * paragraphs separated by HTML paragraph breaks. * * @param variable Description text text text. * @return Description text text text. */ public int methodName (...) { // method body with a return statement } 
+6
source
 /* ... */ 

- just a comment.

 /** ... */ 

is javadoc, which can then be converted to good HTML documentation using a tool, which, oddly enough, is javadoc . This tool considers the javadoc comment itself, the declaration of the class / interface / method and any other implementations / contracts of super / subclasses (for example, when creating information about the "specified" and "overriding" methods). The most notable example of this is the Java SE API document itself .

This documentation comment includes its own markup, such as @see Bar . It can determine program considerations, such as method parameters and their descriptions, the type of method returned, the exceptions that are declared to the method, and the circumstances under which they will be thrown, and other information.

For example, ArrayList#toArray() documented as

public <T> T[] toArray(T[] a)

Returns an array containing all the elements in this list, the correct sequence (from the first to the last element); runtime type Return array - An array of the specified array. If the list matches the specified array, it is returned in it. Otherwise, the new array selected by the runtime type of the specified array and the size of this list.

If the list corresponds to the specified array with a spare number (i.e. the array has more elements than the list), the element in the array is immediately set to null after the collection ends. (This is useful in determining the length of a list only if the caller knows that the list does not contain any null elements.)

It is indicated:
toArray in Collection interface
It is indicated:
toArray in the List interface
Redefinition:
toArray in class AbstractCollection
Type parameters:
T - type of runtime array containing a collection of Parameters:
a - an array in which list items should be stored, if it is large enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Return:
array containing list items
Throws:
ArrayStoreException - if the execution type of the specified array is not a supertype of the execution time of each element in this list
NullPointerException - if the specified array is null

from

  /** * Returns an array containing all of the elements in this list in proper * sequence (from first to last element); the runtime type of the returned * array is that of the specified array. If the list fits in the * specified array, it is returned therein. Otherwise, a new array is * allocated with the runtime type of the specified array and the size of * this list. * * <p>If the list fits in the specified array with room to spare * (ie, the array has more elements than the list), the element in * the array immediately following the end of the collection is set to * <tt>null</tt>. (This is useful in determining the length of the * list <i>only</i> if the caller knows that the list does not contain * any null elements.) * * @param a the array into which the elements of the list are to * be stored, if it is big enough; otherwise, a new array of the * same runtime type is allocated for this purpose. * @return an array containing the elements of the list * @throws ArrayStoreException if the runtime type of the specified array * is not a supertype of the runtime type of every element in * this list * @throws NullPointerException if the specified array is null */ 
+3
source

They are 3 types of comments in java:

Single Comment ligne

 // This is a single line comment 

Multi-line comment

 /* This is a multi-line comment */ 

Documentation Comment

 /** * This is a <b>documentation comment</b> */ 

The compiler will ignore all of them, but the javadoc tool will use doc comments to generate javadoc, you can use HTML formatting there. You can also use a tag like @see or @author

0
source

Source: https://habr.com/ru/post/1207537/


All Articles