generic collection type resolution respects upper bound as well

This commit is contained in:
Juergen Hoeller
2009-02-13 09:09:56 +00:00
parent 483104f0fa
commit e58d036c73
4 changed files with 42 additions and 14 deletions

View File

@@ -341,9 +341,16 @@ public abstract class GenericCollectionTypeResolver {
}
}
if (paramType instanceof WildcardType) {
Type[] lowerBounds = ((WildcardType) paramType).getLowerBounds();
if (lowerBounds != null && lowerBounds.length > 0) {
paramType = lowerBounds[0];
WildcardType wildcardType = (WildcardType) paramType;
Type[] upperBounds = wildcardType.getUpperBounds();
if (upperBounds != null && upperBounds.length > 0 && !Object.class.equals(upperBounds[0])) {
paramType = upperBounds[0];
}
else {
Type[] lowerBounds = wildcardType.getLowerBounds();
if (lowerBounds != null && lowerBounds.length > 0 && !Object.class.equals(lowerBounds[0])) {
paramType = lowerBounds[0];
}
}
}
if (paramType instanceof ParameterizedType) {

View File

@@ -40,7 +40,7 @@ public class GenericCollectionTypeResolverTests extends AbstractGenericsTests {
this.targetClass = Foo.class;
this.methods = new String[] {"a", "b", "b2", "b3", "c", "d", "d2", "d3", "e", "e2", "e3"};
this.expectedResults = new Class[] {
Integer.class, null, null, Set.class, null, Integer.class,
Integer.class, null, Set.class, Set.class, null, Integer.class,
Integer.class, Integer.class, Integer.class, Integer.class, Integer.class};
}