mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
获取别名支持后的注解
This commit is contained in:
@@ -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 "";
|
||||
}
|
||||
|
@@ -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(){
|
||||
|
Reference in New Issue
Block a user