Tag: type annotation

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

似乎getAnnotatedParameterTypes()返回一个包含原始类型而不是generics类型的AnnotatedType数组。 例如: public void genericMethod(T t) { } @Test public void testAnnotatedTypes() throws ReflectiveOperationException { Method method = getClass().getMethod(“genericMethod”, Object.class); Type type = method.getGenericParameterTypes()[0]; assertTrue(type instanceof TypeVariable); AnnotatedType annotatedType = method.getAnnotatedParameterTypes()[0]; // This fails; annotatedType implements only AnnotatedType assertTrue(annotatedType instanceof AnnotatedTypeVariable); // This fails too; type is a TypeVariable while annotatedType.getType() is // Object.class assertEquals(type, […]