我有 POJO 课
Class Book {
private String id;
private String title;
Public Book() {
}
//implement setter and getter
..............
}
main() {
Book book = new Book();
book.setId(1);
book.setTitle("new moon");
}
如何获取 book 对象的所有实例变量我希望结果变为 -> 1,“新月”而不使用 getter 方法,这样我就可以转换其他 POJO 对象。
澄清:
我有 2 节课
Book {
String id;
String title;
//constructor
//setter
}
Student {
String id;
String name;
//cuonstructor
//setter
}
main() {
Book book = new Book();
book.setId(1);
book.setTitle("new moon");
Student student = new Student();
student.setId(1);
student.setName("andrew");
//suppose i have BeanUtil object to get all instance varable value and class meta data
BeanUtil.getMetadata(book, Book.class);
//output is
//id, title
//suppose i have BeanUtil object to get all instance varable value and class meta data
BeanUtil.getMetadata(student, Students.class);
//output is
//id, name
BeanUtil.getInstanceVariableValue(student, Student.class);
//output
//1, andrew
BeanUtil.getInstanceVariableValue(book, Book.class);
//output
//1, new moon
}