Preface:Now the Java production Place Sun does not define a Java annotation specification, the annotation specification is currently each company has its own set of specifications, mainly for the collaboration between the team.1. Basic Rules1. Comments should make the code more readable 2. Note to be concise, simply provide the information necessary to clearly understand the program. If the comment is too complex, it can affect the cleanliness and reading of the program. 3. Note Not only describes what the program does, but also describes why and how it is constrained. 4. There is no comment for the general getter and setter methods. 5. Classes, interfaces, constructors, methods, global variables must be annotated. Field properties you can choose to add a simple comment. 6. Simple annotations generally do not exceed 10 words. 7. Notes must be added to the special place. For example, a few places: the typical algorithm, the code is not clear, at the code modification, in the loop and logical branches to make up the code, for others to provide the interface.2, three kinds of annotation methods 1. Single-line comment (single-line)://note content can only comment one line at a time, usually a simple comment, used to briefly describe a variable or property, the program block. 2. Block Comments (Blocks):/* Comment content * * In order to make multiple lines of simple comments, generally not used. 3. Documentation Notes:/** comments * * Can use multiple lines, generally used to describe classes, interfaces, member methods, member variables, static fields, static methods, constants. Javadoc can use it to generate code for the document. For readability, you can have indentation and formatting controls. Document annotations often use some Javadoc tags for a specific purpose description of the document to help Javadoc produce the document, commonly used:
| Label |
Use |
Description |
| @author Name |
Class/interface |
Describes the author of the code, with each author corresponding to a label. |
| @Description |
Class/Interface/method |
A simple description of the class, method, and interface |
| @deprecated |
Class/Member Method |
Indicates that the API has been revoked. |
| @exception Name Description or @throws name description |
Member Methods |
Describes the exception that the method throws, each of which corresponds to a label |
| @param name Description |
Member Methods |
Describes the use and meaning of parameters in member methods, one parameter corresponds to a label |
| @return Description |
Member Methods |
Describe the meaning of the return value of a member method |
| @since |
Class/Interface/member methods |
Describes the initial occurrence of the API, can be filled out version number |
| @see ClassName |
Class/Interface/member method/member variable |
A description of the member method used to refer to a particular class, reference steering, General classname is a full name that includes the package name |
| @data |
Class/Interface/method |
Used to display classes, methods, interface-specific creation time, or modified time |
| @version text |
Class/interface |
Version |
| @inheritDoc |
Class/Interface/member methods |
Inherited documents |
| {@link address} or @ Linkplain address text} |
Class/Interface/method |
Used to create a hyperlink to another document |
3. Example 1. File comments are generally described in more detail, and are used uniformly within the same project, mainly including: Copyright notice, license license description. example (from spring-framework):/* * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by applic Able law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, * without Warranties or CONDITIONS of any KIND, either express OR implied. * See the License for the specific language governing permissions and * limitations under the License. */ 2. class/interface annotations classes, interface descriptions, generally described in detail. In the usual order of instructions, including 1. Class description to. Or. End. 2. The goal of class design, the completion of what kind of function is generally combined with the description of the class. &NBSP; 3.<strong> the main class uses </Strong> how to use the class, including environmental requirements such as whether the thread is secure, concurrency requirements, and the use of constraints. 4.<strong> known bug</strong> 5. Describe the modification history of a class: & Lt strong> modifier + Date + simple description </Strong> [email protected] author, @version version, @see reference, @ Since start version Info example (from spring-framework): /** * Delegate for resolving constructors and Factory methods. * Performs constructor resolution through argument matching. * * @author Juergen Hoeller * @author Rob Harrop * @author Mark Fisher * @author Costin Leau * @since 2.0 * @see #au Towireconstructor * @see #instantiateUsingFactoryMethod * @see abstractautowirecapablebeanfactory */   ; 3. Method comments Method Description Description, mainly describes the description of the method, parameters, return values, throw exceptions. Example (from Spring-framework) /** * Resolve The factory method in the specified bean def Inition, if possible. * {@link rootbeandefinition#gEtresolvedfactorymethod ()} can is checked for the result. * @param mbd The bean definition to check * @return a beanwrapper for the new instance * @throws Exception Y kind of processing failure */ 4. Modify comments Be sure to add a comment at the point of modification, explaining who modified it, why, what modified it, and when
Java Annotation Specification