Como obter informações de tipo genérico de getAnnotatedParameterTypes () no Java 8?
Parece quegetAnnotatedParameterTypes()
retorna uma matriz deAnnotatedType
s mantendo tipos brutos, e não genéricos. Por exemplo:
public <T> 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, annotatedType.getType());
}
Qual é o motivo do desacordo comgetGenericParameterTypes()
?