mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
feat: ReflectUtil中加入通过条件过滤选择属性
ReflectUtil中加入通过条件过滤选择属性
This commit is contained in:
parent
26c4a44adc
commit
6bbd8451fb
@ -15,13 +15,7 @@ import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 反射工具类
|
||||
@ -188,6 +182,24 @@ public class ReflectUtil {
|
||||
return FIELDS_CACHE.put(beanClass, allFields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得一个类中所有满足条件的字段列表,包括其父类中的字段<br>
|
||||
* 如果子类与父类中存在同名字段,则这两个字段同时存在,子类字段在前,父类字段在后。
|
||||
*
|
||||
* @param beanClass 类
|
||||
* @param fieldFilter field过滤器,过滤掉不需要的field
|
||||
* @return 字段列表
|
||||
* @throws SecurityException 安全检查异常
|
||||
*/
|
||||
public static Field[] getFields(Class<?> beanClass, Filter<Field> fieldFilter) throws SecurityException {
|
||||
final Field[] fields = getFields(beanClass);
|
||||
if (ArrayUtil.isEmpty(fields)) {
|
||||
return fields;
|
||||
}
|
||||
return ArrayUtil.filter(fields, fieldFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得一个类中所有字段列表,直接反射获取,无缓存<br>
|
||||
* 如果子类与父类中存在同名字段,则这两个字段同时存在,子类字段在前,父类字段在后。
|
||||
@ -917,7 +929,7 @@ public class ReflectUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if(method.isDefault()){
|
||||
if (method.isDefault()) {
|
||||
// 当方法是default方法时,尤其对象是代理对象,需使用句柄方式执行
|
||||
// 代理对象情况下调用method.invoke会导致循环引用执行,最终栈溢出
|
||||
return MethodHandleUtil.invokeSpecial(obj, method, args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user