mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
commit
6b86ca2e5d
@ -108,9 +108,17 @@ public class KClassUtil {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T newInstance(final Class<T> targetType, final ValueProvider<String> valueProvider) {
|
public static <T> T newInstance(final Class<T> targetType, final ValueProvider<String> valueProvider) {
|
||||||
final List<?> constructors = getConstructors(targetType);
|
final List<?> constructors = getConstructors(targetType);
|
||||||
|
RuntimeException exception = null;
|
||||||
for (final Object constructor : constructors) {
|
for (final Object constructor : constructors) {
|
||||||
final Object[] parameterValues = getParameterValues(constructor, valueProvider);
|
final Object[] parameterValues = getParameterValues(constructor, valueProvider);
|
||||||
return (T) KCallable.call(constructor, parameterValues);
|
try {
|
||||||
|
return (T) KCallable.call(constructor, parameterValues);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
exception = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (exception != null) {
|
||||||
|
throw exception;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user