ignore bridge

This commit is contained in:
Looly 2021-11-24 23:44:17 +08:00
parent 30515f0351
commit 99763a32b3
3 changed files with 21 additions and 14 deletions

View File

@ -24,6 +24,7 @@
* 【core 】 DateUtil.toIntSecond标记为弃用issue#I4JHPR@Gitee
* 【db 】 Db.executeBatch标记一个重载为弃用issue#I4JIPH@Gitee
* 【core 】 增加CharSequenceUtil.subPreGbk重载issue#I4JO2E@Gitee
* 【core 】 ReflectUtil.getMethod排除桥接方法pr#1965@Github
*
### 🐞Bug修复
* 【core 】 修复FileResource构造fileName参数无效问题issue#1942@Github

View File

@ -2551,7 +2551,12 @@ public class CharSequenceUtil {
}
/**
* 比较两个字符串是否相等
* 比较两个字符串是否相等规则如下
* <ul>
* <li>str1和str2都为{@code null}</li>
* <li>忽略大小写使用{@link String#equalsIgnoreCase(String)}判断相等</li>
* <li>不忽略大小写使用{@link String#contentEquals(CharSequence)}判断相等</li>
* </ul>
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2

View File

@ -84,7 +84,7 @@ public class ReflectUtil {
@SuppressWarnings("unchecked")
public static <T> Constructor<T>[] getConstructors(Class<T> beanClass) throws SecurityException {
Assert.notNull(beanClass);
return (Constructor<T>[]) CONSTRUCTORS_CACHE.get(beanClass, ()->getConstructorsDirectly(beanClass));
return (Constructor<T>[]) CONSTRUCTORS_CACHE.get(beanClass, () -> getConstructorsDirectly(beanClass));
}
/**
@ -173,7 +173,7 @@ public class ReflectUtil {
*/
public static Field[] getFields(Class<?> beanClass) throws SecurityException {
Assert.notNull(beanClass);
return FIELDS_CACHE.get(beanClass, ()->getFieldsDirectly(beanClass, true));
return FIELDS_CACHE.get(beanClass, () -> getFieldsDirectly(beanClass, true));
}
@ -498,11 +498,9 @@ public class ReflectUtil {
}
/**
* 查找指定方法 如果找不到对应的方法则返回{@code null}
*
* <p>
* 此方法为精准获取方法名即方法名和参数数量和类型必须一致否则返回{@code null}
* </p>
* 查找指定方法 如果找不到对应的方法则返回{@code null}<br>
* 此方法为精准获取方法名即方法名和参数数量和类型必须一致否则返回{@code null}<br>
* 如果查找的方法有多个同参数类型重载查找第一个找到的方法
*
* @param clazz 如果为{@code null}返回{@code null}
* @param ignoreCase 是否忽略大小写
@ -520,10 +518,11 @@ public class ReflectUtil {
final Method[] methods = getMethods(clazz);
if (ArrayUtil.isNotEmpty(methods)) {
for (Method method : methods) {
if (StrUtil.equals(methodName, method.getName(), ignoreCase)) {
if (ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes)) {
return method;
}
if (StrUtil.equals(methodName, method.getName(), ignoreCase)
&& ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes)
//排除桥接方法pr#1965@Github
&& false == method.isBridge()) {
return method;
}
}
}
@ -586,7 +585,9 @@ public class ReflectUtil {
final Method[] methods = getMethods(clazz);
if (ArrayUtil.isNotEmpty(methods)) {
for (Method method : methods) {
if (StrUtil.equals(methodName, method.getName(), ignoreCase)) {
if (StrUtil.equals(methodName, method.getName(), ignoreCase)
// 排除桥接方法
&& false == method.isBridge()) {
return method;
}
}
@ -635,7 +636,7 @@ public class ReflectUtil {
*/
public static Method[] getMethods(Class<?> beanClass) throws SecurityException {
Assert.notNull(beanClass);
return METHODS_CACHE.get(beanClass, ()-> getMethodsDirectly(beanClass, true));
return METHODS_CACHE.get(beanClass, () -> getMethodsDirectly(beanClass, true));
}
/**