查看系统代码学习注解笔记

回顾注解的格式

ElementType.TYPE表示注解作用范围在type表示可以作用在class,method,filed里,如果是method表示只能作用在该方法,如果是filed则只能作用该字段上
RetentionPolicy.RUNTIME表示运行时有效,如果是source表示只在当前源码有效,class,表示在该类有效,一般自定义注解都为runtime
Documented表示是否生成在java文档中
Inherit表示子类可以继承父类的注解
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherit

public interface 注解名{}

 

自定义注解:其中default表示默认值为空

@Target({ElementType.METHOD, ElementType.TYPE})

@Retention(RetentionPolicy.RUNTIME)

@interface   MyAnnotation{

String    name() default" "

}

posted @ 2023-09-06 13:46  Zzzz/  阅读(17)  评论(0)    收藏  举报