Java中如何通过反射机制获取班级对象中的学生姓名?
Field[] classField = Class_.class.getDeclaredFields(); Field f=Class_.class.getDeclaredField('student'); f.setAccessible(true); Student student= (Student) f.get(c); Field[] studentField=student.getClass().getDeclaredFields(); for(Field field:studentField){ field.setAccessible(true); System.out.println(field.get(student)); }
赞0
踩0