Fix wrong cast.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@984655 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joerg Schaible 2010-08-12 06:47:43 +00:00
parent 8904051249
commit 37dba589f7
1 changed files with 8 additions and 6 deletions

View File

@ -265,14 +265,13 @@ public class ConstructorUtils {
} }
Constructor<T> result = null; Constructor<T> result = null;
/* /*
* Class.getConstructors() is documented to return Constructor<T> so as * (1) Class.getConstructors() is documented to return Constructor<T> so as
* long as the array is not subsequently modified, everything's fine: * long as the array is not subsequently modified, everything's fine.
*/ */
@SuppressWarnings("unchecked") // cls is of type T Constructor<?>[] ctors = cls.getConstructors();
Constructor<T>[] ctors = cls.getConstructors();
// return best match: // return best match:
for (Constructor<T> ctor : ctors) { for (Constructor<?> ctor : ctors) {
// compare parameters // compare parameters
if (ClassUtils.isAssignable(parameterTypes, ctor.getParameterTypes(), true)) { if (ClassUtils.isAssignable(parameterTypes, ctor.getParameterTypes(), true)) {
// get accessible version of constructor // get accessible version of constructor
@ -282,7 +281,10 @@ public class ConstructorUtils {
if (result == null if (result == null
|| MemberUtils.compareParameterTypes(ctor.getParameterTypes(), result || MemberUtils.compareParameterTypes(ctor.getParameterTypes(), result
.getParameterTypes(), parameterTypes) < 0) { .getParameterTypes(), parameterTypes) < 0) {
result = ctor; // temporary variable for annotation, see comment above (1)
@SuppressWarnings("unchecked")
Constructor<T> constructor = (Constructor<T>)ctor;
result = constructor;
} }
} }
} }