I have a lots of classes for example this one:
public class DepartmentST {
public Long id = null;
public String name = null;
public String comments = null;
public Long[] profiles = null;
public Boolean default_val = false;
}
In main class I create objects of those classes and sent it to general method for example:
DepartmentST mydepartment = new DepartmentST();
generalMethod(mydepartment);
In general Method I want to access to object fields (this my question how?)
public generalMethod(Object myObj) {
Field[] fields = myObj.getClass().getFields();
for(Field field : fields) {
String fieldName = field.getName();
// I want to access that field how can i tell myObj.fielName ?
}
}
I'm new in Java I don't know it's stupid question or not.
thanks for any help in advance.