!827 注解工具类支持Lambda获取某注解属性值

Merge pull request !827 from 嗯嗯/v5-dev
This commit is contained in:
Looly
2022-09-30 11:04:46 +00:00
committed by Gitee
3 changed files with 37 additions and 4 deletions

View File

@@ -26,4 +26,6 @@ public @interface AnnotationForTest {
@Alias("value")
String retry() default "";
String[] names() default "";
}

View File

@@ -1,5 +1,7 @@
package cn.hutool.core.annotation;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ReflectUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -34,6 +36,12 @@ public class AnnotationUtilTest {
}
@Test
public void getAnnotationValueTest2() {
String[] names = AnnotationUtil.getAnnotationValue(ClassWithAnnotation.class, AnnotationForTest::names);
Assert.assertTrue(ArrayUtil.equals(names, new String[]{"测试1", "测试2"}));
}
@Test
public void getAnnotationSyncAlias() {
// 直接获取
@@ -45,7 +53,7 @@ public class AnnotationUtilTest {
Assert.assertTrue(AnnotationUtil.isSynthesizedAnnotation(annotation));
}
@AnnotationForTest("测试")
@AnnotationForTest(value = "测试", names = {"测试1", "测试2"})
@RepeatAnnotationForTest
static class ClassWithAnnotation{
public void test(){