Is there any open source utility or jar for handling reflection in java?
I am passing methods Dynamically to a class and I would like to fetch the return value.
For Example:
class Department {
String name ;
Employee[] employees;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public Employee[] getEmployes() {
return employees;
}
}
I would like to print all the employees to the console output but instead getting it at run-time like this:
Department dept = new Department();
// add employees..
getEmployeeNames(dept,"getEmployees.getAddress.getStreet");
// So the user says they want employee street, but we don't know that
// until run-tme.
Is there any opensource on reflection to accommodate something like this?
This kind of thing always rings design alarm bells when I see it.
That being said, I usually think that JXPath ( http://commons.apache.org/jxpath/users-guide.html ) is the most reasonable solution for that type of problem if it can’t be solved in a more engineered way: