Notes on java learning

Notes on java learning

0x00 Preface

Continuing with the previous article, this article will write about the relevant contents of the annotation.

0x01 annotation overview

Java annotation, also known as Java annotation, is an annotation mechanism for jdk5.0 dating. Unlike Javadoc, Java annotation can obtain annotation content through reflection. When the compiler generates class files, annotations can be embedded into bytecode. Java virtual machine can retain annotation content and obtain annotation content at runtime. Of course, it also supports custom Java annotations.

It is jdk1 A feature introduced in version 5 and later is at the same level as class, interface and enumeration. It can be declared in front of packages, classes, fields, methods, local variables, method parameters, etc. to describe and annotate these elements.

Function classification: ① document writing: generate document doc document through the metadata identified in the code ② code analysis: analyze the code through the metadata identified in the code [use reflection] ③ compilation check: enable the compiler to realize basic compilation check through the metadata identified in the code [override]

0x02 annotation definition

JDK's own annotations

* @Override	:检测被该注解标注的方法是否是继承自父类(接口)的
	* @Deprecated:该注解标注的内容,表示已过时
	* @SuppressWarnings:压制警告

Deprecated annotation:

@Deprecated
    public void method1(){
        System.out.println("a");
    }

After being modified by the annotation, it means that the method is outdated, and a horizontal line will appear when calling.

Word definition annotation

Format:

		元注解
		public @interface 注解名称{
			属性列表;
		}

MyAnoin:

package Domain;

public @interface MyAnoin {
    int age();
    String name() default "zhangshan"; //默认值为zhangshan
    String[] strs();     //数组

}

shu:

package Domain;
@MyAnoin(age = 1,name = "lishi",strs={"abc","ii"})
public class zhu {

}

0x03 end

The content of this article is not much. It should have been put together with the previous article. It's better to separate it. It will also be easy to find.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>