Looking at the Crud object code below, what I'm expecting is an array of Field objects for type T. What I appear to actually get is an empty array of of Field objects for type Object. My test class is called Timezone. So, when I instantiate the Crud object it looks like...
Crud<Timezone> tz = new Crud<Timezone>();
But as I said this isn't working. Help appreciated.
import java.util.*;
import java.lang.reflect.*;
public class Crud<T> {
public T getInstance()
{
@SuppressWarnings("unchecked")
T object = (T) new Object();
return object;
}
public ArrayList<String> getMembers() {
ArrayList<String> retval = new ArrayList<String>();
try {
T object = this.getInstance();
Field[] fields = object.getClass().getDeclaredFields(); //Always empty
for (Field field : fields) {
retval.add(field.getName());
}
} catch (Exception e) {
System.out.println(e);
}
return retval;
}
}