ScottTiger
asked on
Retrieving all properties for an object
I want to accept and object and loop through all of its properties.
I am looking for a method to do this regardless of the object.
My goal is to make a string of the properties.
Example:
public String ReturnConcat (myObject objMYObject)
{
this.<loop through properties> (objMyObject);
String(x) = String(x) + String(y)
log.String(x)
}
I am looking for a method to do this regardless of the object.
My goal is to make a string of the properties.
Example:
public String ReturnConcat (myObject objMYObject)
{
this.<loop through properties> (objMyObject);
String(x) = String(x) + String(y)
log.String(x)
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't think you can do that with ordinary Java object except for Javabean. If you really want to do that, all properties of the object should have a getter method which is in the form of getXXX() where XXX is the property name starting with a capital letter. For example, if the property name is width, you should have corresponding getWidth() method. That's what we call introspection. In Javabeans, it is standard to provide the setter and getter methods but if you want to have a method with different name you can do so by providing BeanInfo (which I'm not familiar with)
Jerson
Jerson
ASKER
I am very pleased by your answer, but am looking for obtaining the actual value for the properties, not the names.