【annotation】directly present, indirectly present, present, and associated

本文详细解释了Java注解中的directly present, indirectly present, present, 和 associated的含义,并通过测试代码进行验证。directly present指注解直接在元素上,present包括直接和间接存在,indirectly present涉及重复注解,associated则考虑了继承。文章还介绍了Java反射API中获取注解的不同方法及其行为。" 114589118,10543352,Java安全管理器:使用与权限配置,"['java security manager', '权限管理']
摘要由CSDN通过智能技术生成

一、directly present, indirectly present, present, and associated

question

在API文档中,获取Java注解的方法的返回值注释directly presentindirectly presentpresent, and associated是什么含义?

引子

API documentation:AnnotatedElement (Java SE 15 & JDK 15) (oracle.com)

The terms directly presentindirectly presentpresent, and associated are used throughout this interface to describe precisely which annotations are returned by methods:

  • An annotation A is directly present on an element E if E has a RuntimeVisibleAnnotations or RuntimeVisibleParameterAnnotations or RuntimeVisibleTypeAnnotations attribute, and the attribute contains A.
  • An annotation A is indirectly present on an element E if E has a RuntimeVisibleAnnotations or RuntimeVisibleParameterAnnotations or RuntimeVisibleTypeAnnotations attribute, and A 's type is repeatable, and the attribute contains exactly one annotation whose value element contains A and whose type is the containing annotation type of A 's type.
  • An annotation A is present on an element E if either:
    • A is directly present on E; or
    • No annotation of A 's type is directly present on E, and E is a class, and A 's type is inheritable, and A is present on the superclass of E.
  • An annotation A is associated with an element E if either:
    • A is directly or indirectly present on E; or
    • No annotation of A 's type is directly or indirectly present on E, and E is a class, and A's type is inheritable, and A is associated with the superclass of E.

The table below summarizes which kind of annotation presence different methods in this interface examine.

Overview of kind of presence detected by different AnnotatedElement methods
Method Kind of Presence
Return Type Signature Directly Present Indirectly Present Present Associated
T getAnnotation(Class<T>)     X  
Annotation[] getAnnotations()     X  
T[]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值