草庐IT

getAnnotatedParameterTypes

全部标签

java - 为什么 getAnnotatedParameterTypes 看不到数组类型的注释?

出于某种原因,我不明白为什么这段代码打印出true和false,array有什么特别之处,它不包括此处的注释?如果您改为使用getParameters,它将按预期工作。importjava.lang.annotation.*;@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE_USE,ElementType.PARAMETER})@interfaceLel{}classTest{publicstaticvoida(@LelStringargs){}publicstaticvoidb(@LelString[]args)

java - 如何从 Java 8 中的 getAnnotatedParameterTypes() 获取泛型类型信息?

似乎getAnnotatedParameterTypes()返回一个包含原始类型而非通用类型的AnnotatedType数组。例如:publicvoidgenericMethod(Tt){}@TestpublicvoidtestAnnotatedTypes()throwsReflectiveOperationException{Methodmethod=getClass().getMethod("genericMethod",Object.class);Typetype=method.getGenericParameterTypes()[0];assertTrue(typeinstan