Java 4种元注解

@Tatget 范围(在类上,方法上,还是字段上生效),表示可以用在那些地方

@Retention:定义什么时候生效,有三重,Source,Class, RunTime,一般为RunTime有效。表示我们的注解什么时候有效。RunTime》Class》Source
@Documented:表示是否将我们的注解是否生成在JavaDOC中
@Inherited:子类可以继承父类的注解

定义一个注解:

//@Target(value = {ElementType.METHOD,ElementType.TYPE,Filds})//用在方法上,类上,字段上
@Target(value = ElementType.METHOD)//用在方法上
@Retention(value =RetentionPolicy.RUNTIME)//运行时都还有效果
@interface MyAnnotation(){
    
    
}

笔记:

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39463175/article/details/118401920