mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-15 05:13:18 +08:00
!837 ReflectUtil.invokeRaw方法 对检查用户传入参数时,对于类型不同的字段,尝试转换,转换失败后的操作
Merge pull request !837 from 高邮湖徐先生/v5-dev
This commit is contained in:
commit
f31eb8512e
@ -846,7 +846,7 @@ public class ReflectUtil {
|
|||||||
public static <T> T newInstance(Class<T> clazz, Object... params) throws UtilException {
|
public static <T> T newInstance(Class<T> clazz, Object... params) throws UtilException {
|
||||||
if (ArrayUtil.isEmpty(params)) {
|
if (ArrayUtil.isEmpty(params)) {
|
||||||
final Constructor<T> constructor = getConstructor(clazz);
|
final Constructor<T> constructor = getConstructor(clazz);
|
||||||
if(null == constructor){
|
if (null == constructor) {
|
||||||
throw new UtilException("No constructor for [{}]", clazz);
|
throw new UtilException("No constructor for [{}]", clazz);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -1056,7 +1056,7 @@ public class ReflectUtil {
|
|||||||
actualArgs[i] = null;
|
actualArgs[i] = null;
|
||||||
} else if (false == parameterTypes[i].isAssignableFrom(args[i].getClass())) {
|
} else if (false == parameterTypes[i].isAssignableFrom(args[i].getClass())) {
|
||||||
//对于类型不同的字段,尝试转换,转换失败则使用原对象类型
|
//对于类型不同的字段,尝试转换,转换失败则使用原对象类型
|
||||||
final Object targetValue = Convert.convert(parameterTypes[i], args[i]);
|
final Object targetValue = Convert.convertQuietly(parameterTypes[i], args[i], args[i]);
|
||||||
if (null != targetValue) {
|
if (null != targetValue) {
|
||||||
actualArgs[i] = targetValue;
|
actualArgs[i] = targetValue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user