Discuss the function of @param annotation and @see annotation in Java

  • 2020-04-01 04:32:33
  • OfStack

@ param
The @param tag can archive a single argument to a method or constructor, or type arguments to an archive class, interface, and generic method. When using the @param tag, we should use one for each parameter of the method. The first word of each paragraph is used as the argument name, and the rest is used as a description of it:


  @param max The maximum number of words to read.

When archiving type parameters, we should add < to both sides of the type parameter name. And > :


  @param one e element type of this List

However, type parameters usually do not require explicit documentation because their meaning is obvious.

@ see
The @see tag can create cross-references linking to other javadoc documents. We can name any identifier after the label, although we must qualify them sufficiently. For example, it is common to name a class by the simple name of its member, but if the member is an overloaded method, we must specify the overloaded version of the method by enumerating the types of each argument. We can specify interfaces or classes in the current package with unqualified names, but we must specify types in other packages with fully qualified names. We can specify a member of a type by using # before the member name. Here are all valid @see tag formats:


  @see #getName

  @see Attr

  @see com.magic.attr.Attr

  @see com.magic.attr.Deck#DECK-SIZE

  @see com.magic.attr.Attr#getName

  @see com.magic.attr.Attr#Attr(String)

  @see com.magic.attr.Attr#Attr(String . Object)

  @see com.magic.attr

  @see Attribute Specification

  @see "The Java Developer's Almanac"

The first form refers to a method called getName that is in the same class or interface as the document annotation itself, or in some enclosing class or enclosing interface, and the syntax can also be applied to constructors and fields. The second form refers to a class in the current package or a class in some guide package. The third form references a class with a fully qualified name.

The last four forms of @see refer to members, of which the first two are in the form of fields (deck-siz day and method (getName). We can use the method name directly because there is only one getName method defined in the Attr class. The latter two refer to the constructor of the Attr class, one of which accepts string arguments and the other accepts strings and objects. When a constructor or method has an overloaded version, we must specify the argument for the overloaded version we want to reference.

The following @see form leads the reader to a specific package :com.magic.attro

The last two forms allow us to refer to other documents. The first USES links to define links, and the second USES quotes to enclose the document name. We can use these two forms to guide the reader to other documents, such as a complete instruction manual.

The @see form (all but the last two above) that names a language entity can be followed by a label. In the generated document, the label name will replace the entity name. Such as:


  @ see #getNameAttribute Names

A link to the document getName is created, but the text it displays is "Attribute Names" instead of "getName". Normally we should use the real names of the members, but the features shown here are occasionally useful.


Related articles: