提交 610e7796 编写于 作者: J Juergen Hoeller

GenericTypeResolver properly handles bound parameterized type

Issue: SPR-10819
(cherry picked from commit ea6525f1)
上级 8efac21c
......@@ -305,7 +305,7 @@ public abstract class GenericTypeResolver {
}
/**
* Extract a class instance from given Type.
* Extract a Class from the given Type.
*/
private static Class<?> extractClass(Class<?> ownerClass, Type arg) {
if (arg instanceof ParameterizedType) {
......@@ -322,9 +322,12 @@ public abstract class GenericTypeResolver {
arg = getTypeVariableMap(ownerClass).get(tv);
if (arg == null) {
arg = extractBoundForTypeVariable(tv);
if (arg instanceof ParameterizedType) {
return extractClass(ownerClass, ((ParameterizedType) arg).getRawType());
}
}
else {
arg = extractClass(ownerClass, arg);
return extractClass(ownerClass, arg);
}
}
return (arg instanceof Class ? (Class) arg : Object.class);
......
......@@ -19,7 +19,6 @@ package org.springframework.core;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
......@@ -27,7 +26,6 @@ import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.springframework.core.GenericTypeResolver.*;
import static org.springframework.util.ReflectionUtils.*;
......@@ -76,7 +74,6 @@ public class GenericTypeResolverTests {
*/
@Test
public void genericMethodReturnTypes() {
Method notParameterized = findMethod(MyTypeWithMethods.class, "notParameterized", new Class[] {});
assertEquals(String.class, resolveReturnTypeForGenericMethod(notParameterized, new Object[] {}));
......@@ -151,6 +148,11 @@ public class GenericTypeResolverTests {
assertEquals(Integer[].class, resolveType(genericArrMessageMethodParam.getGenericParameterType(), varMap));
}
@Test
public void testBoundParameterizedType() {
assertEquals(B.class, resolveTypeArgument(TestImpl.class, ITest.class));
}
public interface MyInterfaceType<T> {
}
......@@ -250,4 +252,13 @@ public class GenericTypeResolverTests {
static class GenericClass<T> {
}
class A{}
class B<T>{}
class ITest<T>{}
class TestImpl<I extends A, T extends B<I>> extends ITest<T>{
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册