java.lang.reflect 包

java.lang.reflect 包的结构

目录

java.lang.reflect 包的结构


 

整体类结构图:

AnnotatedElement接口的含义,被注解的元素,实现了此接口的类即是可被注解的,jdk中实现此接口的类如下,

AccessibleObjectClassConstructorExecutableFieldMethodPackageParameter(即主要是 类、字段、方法、参数、构造函数)

接口定义了如下方法,用于判断注解是否存在或获取注解:

isAnnotationPresent
getAnnotation
getAnnotations
getAnnotationsByType
getDeclaredAnnotation
getDeclaredAnnotationsByType
getDeclaredAnnotations

jdk1.8中增加了repeatable 元注解,被此注解标注的注解可用多次注解同一AnnotatedElement,如spring中

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Repeatable {
    // Repeatable 注解定义时,值需要指定注解的容器类型,
    //例如spring @ComponetScan的定义
    Class<? extends Annotation> value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
@Repeatable(ComponentScans.class)  // 注意为ComponentScans.class
public @interface ComponentScan {
    @AliasFor("basePackages")
    String[] value() default {};
     .....
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
public @interface ComponentScans {
    ComponentScan[] value();  //类型为ComponentScan 数组
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值