一、@AliasFor注解概览
@AliasFor是Spring Framework中的一个注解,从4.2版本开始出现,源码位于spring-core中,用于注解的属性之上,为该属性声明一个别名。
1.1 Spring官方文档说明
查察Spring中的@AliasFor的文档,英文形貌如下:
Usage Scenarios
- Explicit aliases within an annotation: within a single annotation, @AliasFor can be declared on a pair of attributes to signal that they are interchangeable aliases for each other.
- Explicit alias for attribute in meta-annotation: if the annotation attribute of @AliasFor is set to a different annotation than the one that declares it, the attribute is interpreted as an alias for an attribute in a meta-annotation (i.e., an explicit meta-annotation attribute override). This enables fine-grained control over exactly which attributes are overridden within an annotation hierarchy. In fact, with @AliasFor it is even possible to declare an alias for the value attribute of a meta-annotation.
- Implicit aliases within an annotation: if one or more attributes within an annotation are declared as attribute overrides for the same meta-annotation attribute (either directly or transitively), those attributes will be treated as a set of implicit aliases for each other, resulting in behavior analogous to that for explicit aliases within an annotation.
1.2 翻译表明说明
1.2.1 Explicit aliases within an annotation
within a single annotation, @AliasFor can be declared on a pair of attributes to signal that they are interchangeable aliases for each other
意思是注解中的属性可以相互为别名举行利用
1.2.2 Explicit alias for attribute in meta-annotation
if the annotation attribute of @AliasFor is set to a different annotation than the one that declares it, the attribute is interpreted as an alias for an attribute in a meta-annotation (i.e., an explicit meta-annotation attribute override). This enables fine-grained control over exactly which attributes are overridden within an annotation hierarchy. In fact, with @AliasFor it is even possible to declare an alias for the value attribute of a meta-annotation.
大抵意思是注解中利用了元注解时,可以对元注解的值举行重写,目标是为了能到达和类继承中override相似的功能
1.2.3 Implicit aliases within an annotation
if one or more attributes within an annotation are declared as attribute overrides for the same meta-annotation attribute (either directly or transitively), those attributes will be treated as a set of implicit aliases for each other, resulting in behavior analogous to that for explicit aliases within an annotation.
大抵意思是注解中利用了元注解时,可以对元注解的值举行重写,而且可用多个差异的别名举行重写(着实就是一和二的连合)
二、@AliasFor源码说明
2.1 源码 |