当前位置:网站首页>Traversing object properties of unknown type
Traversing object properties of unknown type
2022-06-10 12:06:00 【wfsm】
quote :https://blog.csdn.net/ExceptionalBoy/article/details/79203465
- Reflection acquisition field
- Reflection acquisition getXXX() Method
@Test
public void test02 () throws IllegalAccessException {
Object cc = new Student(1, "cc");
// printBeanField(cc);
printBeanField2(cc);
}
private void printBeanField(Object obj) throws IllegalAccessException {
// Determines if the object is null
if (obj != null){
Field[] fields = obj.getClass().getDeclaredFields();
if (fields != null && fields.length !=0){
for (Field f : fields) {
f.setAccessible(true);
Object fieldValue = f.get(obj);
String fieldName = f.getName();
System.out.println(fieldName+"---"+fieldValue);
}
}
}
}
private void printBeanField2(Object obj) {
if (obj != null){
Method[] methods = obj.getClass().getDeclaredMethods();
if (methods != null && methods.length>0){
Arrays.stream(methods).filter((item)->item.getName().startsWith("get")).forEach(item->{
try {
item.setAccessible(true);
String methodName = item.getName();
Object methodValue = item.invoke(obj);
System.out.println(methodName+"--"+methodValue);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
});
}
}
}
边栏推荐
猜你喜欢

How data is stored in memory
![[extensive reading of papers] distilling the knowledge in a neural network](/img/e3/b834c60364741d671ce07ee8eedf95.png)
[extensive reading of papers] distilling the knowledge in a neural network

更改系统时间

浅谈分布式事务

La poignée d'enseignement de la station B vous apprend à utiliser le masque yolov5 pour tester les éléments de l'enregistrement le plus complet (apprentissage profond / détection d'objets / pythorch)

Transfomer components and pytoch

交出 Firehouse 数据库访问权:推特准备满足马斯克要求

360, Tsinghua | zero and R2D2: a large-scale Chinese cross modal benchmark and visual language Framework

Web server development, small company web development

H5弹出提示层-上下左右居中
随机推荐
js全局计时器的案例
B站教学 手把手教你使用YOLOV5之口罩检测项目 最全记录详解 ( 深度学习 / 目标检测 / pytorch )
The securities and futures industry meets the new data regulation, and IP guard helps improve data security management
Amateurs don't ask for help, drag and drop for 30 seconds to make the cover image
数字经济时代,零售实体门店该何去何从
西骏数据与阿里云携手合作,获得阿里云产品集成认证!
'getdrawable (int) 'is deprecated, getdrawable is obsolete
国际档案日|瀚高数据库以科技赋能数字档案建设
Peking University and Microsoft | progress in reasoning to make language models better
Transfomer components and pytoch
线性代数的本质5 行列式
线性代数的本质6 逆矩阵、列空间与零空间
大型项目综合实训
你对PHP数据类型或者其他编程语言的数据类型了解多少呢
绿盟数据库防火墙(DAS-FW)获得鲲鹏Validated认证
从“化学家”到开发者,从甲骨文到TDengine,我人生的两次重要抉择
The essence of linear algebra 4 matrix multiplication and linear compound transformation
web端开发,web开发选型
Pytorch has fixed parameters and detach clone
C語言最佳實踐之庫文件介紹(下)