How to access the property of an object or a related object, using classmetadata or reflection?
Suppose we have these classes
class Person {
public String name;
public void Person( name ) {
this.name = name;
}
}
class A {
public String name;
public void A(name) {
this.name = name
}
}
class B {
public Person person;
public void A(name) {
this.person = new Person(name)
}
}
As we can see, there are different ways to access the name property
For the first class:
A p = new A("Tom")
// Access to the name
p.name
For the second class
B p = new B("Tom")
// Access to the name
p.person.name
Now suppose that we need from a generic class to access the property name of the 2 classes, but the generic class does not know about this structure. This class would in some way need to access the information on how the structure is. Listen to something like metadata or reflection.
What would be the correct way to obtain and use this information?