私は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オブジェクトの全インスタンス変数を取得する方法 getterメソッドを使わずに結果を→1、「新月」にしたいので、他の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
}