Preliminary study notes

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_44002167/article/details/98523230

First, the concept :

Note: The description of the process, to look at the computer
Notes: The text description of the program. To the programmer's

Definition: Notes (Annotation), also known as metadata. Describe a code level. It is a feature of JDK1.5 and later introduced the classes, interfaces, enumerations are on the same level. It can be declared in front of the packages, classes, fields, methods, local variables, parameters and the like of the method for these elements will be described, the comment.

Role Category:
① documenting: by annotating generate a document [document generation doc documentation] code identified
were the code by annotating code identification analysis [using reflection]: ② code analysis
③ compiler checks: notes by code identified so that the compiler can compile basic checking [Override]

Concept description:

  • After JDK1.5 new features
  • Description of the process
  • Use annotations; @ Name annotation

Two, the JDK predefined number of notes

  • @Override: a method for detecting the labeled annotation whether inherited from the parent class (parent Interface)

  • @Deprecated: The content annotation marked obsolete

  • @SuppressWarnings: suppress warnings

    General parameters passed all @SupressWarning ( "all")

Third, custom annotation

  1. format:

    	原注解
    	Public @interface 注解名称
    
  2. Essence: annotation is essentially a interface that inherits default Annotation Interface

    	Extends java.lang.annotation.Annotation
    
  3. Attribute: Member ways to define the interface

    	要求:
    	1,属性的返回值类型
    		基本数据类型
    		String
    		枚举
    		注解
    		以上 类型的数组
    	2,定义了属性,在使用时需要给属性赋值
    		1,如果定义属性时,使用default关键字给默认初始化值,则使用注解时,可以不进行属性赋值(取默认值)
    		2,如果只有一个属性需要赋值,并且属性的名称是value,则value可以省略,则直接定能一值即可
    		3,数组赋值时,值使用{}包裹,如果数组中只有一个值,{}可以省略
    
  4. Original annotation: annotation is used to describe annotations

    	@Target:描述注解能够作用的位置
    		ElementType取值:
    			Type:可以作用于类上
    			METHOD:可以作用在方法上
    			FIELD:可以作用于成员变量上
    	@Retention: 描述注解被保留的阶段
    		@Retention(RetentionPolicy.RUNTIME):当前被描述的注解,会保留到class字节码文件中,并被JVM读取到
    	@Documented:描述注解是否被抽取到API文档中 
    	@Inherited:描述注解是否被子类继承
    

Fourth, the use of (resolved) in the program notes : getting a property value defined in the annotation

  1. Gets annotation defines the position of the object

  2. Gets the specified comment
    getAnnotation (Class)
    is actually generated a subclass object class annotation interface in memory

  3. Abstract method invocation of the annotation

V. Summary : Most of the time, we will use annotations, rather than custom annotation

Who used to comment:

  1. translater
  2. Used to compile
  3. Annotations are not part of the program

*** *** Reference:
Baidu Encyclopedia: https://baike.baidu.com/item/Java Notes / 4404368
dark horse programmer: https://www.bilibili.com/video/av50351111/?p=9

Guess you like

Origin blog.csdn.net/qq_44002167/article/details/98523230