how iterate over class members java (app-engine)
Posted
by Alexandre H. Tremblay
on Stack Overflow
See other posts from Stack Overflow
or by Alexandre H. Tremblay
Published on 2010-03-17T21:28:03Z
Indexed on
2010/03/17
21:41 UTC
Read the original article
Hit count: 378
Hello, I am using the java version of the google app engine.
I would like to create a function that can receive as parameters many types of objects. I would like to print out the members of the object. Each objects may be different and the function must work for all objects. Do I have to use reflection - if so, what kind of code do I need to write?
public class dataOrganization {
private String name;
private String contact;
private PostalAddress address;
public dataOrganization(){}
}
public int getObject(Object obj){
// This function prints out the name of every
// member of the object, the type and the value
// In this example, it would print out "name - String - null",
// "contact - String - null" and "address - PostalAddress - null"
}
How would I write the function getObject?
© Stack Overflow or respective owner