小编Use*_*111的帖子

如何动态地从pojo中获取字段

下面是我的POJO课程,其中有50个带有setter和getter的字段。

Class Employee{
int m1;
int m2;
int m3;
.
.
int m50;
//setters and getters
Run Code Online (Sandbox Code Playgroud)

在另一堂课中,我需要获得所有这50个字段的总和

Employee e1 =new Emploee();
int total = e1.getM1()+e2.getM2()+........e2.getM50();
Run Code Online (Sandbox Code Playgroud)

无需手动进行50条记录,而是可以通过任何循环动态地进行操作。

谢谢

java variables field pojo

3
推荐指数
1
解决办法
6124
查看次数

标签 统计

field ×1

java ×1

pojo ×1

variables ×1