获取别名支持后的注解

This commit is contained in:
VampireAchao
2022-03-01 22:59:28 +08:00
parent 9c3cf705c6
commit 0e5329850a
3 changed files with 39 additions and 9 deletions

View File

@@ -10,7 +10,6 @@ import java.lang.annotation.Target;
* 注解类相关说明见https://www.cnblogs.com/xdp-gacl/p/3622275.html
*
* @author looly
*
*/
// Retention注解决定MyAnnotation注解的生命周期
@Retention(RetentionPolicy.RUNTIME)
@@ -23,5 +22,8 @@ public @interface AnnotationForTest {
*
* @return 属性值
*/
String value();
String value() default "";
@Alias("value")
String retry() default "";
}

View File

@@ -12,6 +12,16 @@ public class AnnotationUtilTest {
}
@Test
public void getAnnotationSyncAlias() {
// 直接获取
Assert.assertEquals("", ClassWithAnnotation.class.getAnnotation(AnnotationForTest.class).retry());
// 加别名适配
AnnotationForTest annotation = AnnotationUtil.getAnnotationAlias(ClassWithAnnotation.class, AnnotationForTest.class);
Assert.assertEquals("测试", annotation.retry());
}
@AnnotationForTest("测试")
static class ClassWithAnnotation{
public void test(){