!986 【6.x】代码优化

Merge pull request !986 from 阿超/v6-dev
This commit is contained in:
Looly 2023-05-05 03:54:18 +00:00 committed by Gitee
commit 6b86ca2e5d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -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;
} }