Techer类:
class Techer {
private String name;
private String glass;
private List<Student> stus;
}
Student类:
class Student {
private String stuNmae;
private String stuAge;
}
数据结构:
Student stu1 = new Student();
stu1.setStuNmae("zhangsan");
Student stu2 = new Student();
stu2.setStuNmae("lisi");
Techer tec = new Techer();
tec.setGlass("B");
tec.setName("zhang lao shi");
List<Student> stus = new ArrayList<Student>();
stus.add(stu1);
stus.add(stu2);
tec.setStus(stus);
请问,如何通过java的反射机制,修改tec对象中的suts,分别为stu1和stu2的sutAge赋值
接口要求如下:
public Techer setStuInfo(Techer tec, String[] ages);
------解决思路----------------------
Method method = tec.getClass().getMethod("setStus", List.class);
method.invoke(tec, stus);