To obtain the getters, consider using introspection rather than reflection : it is intended for this purpose!
Here is a code to automatically obtain the getters. Beware, you also get "getClass()" getter!
for(PropertyDescriptor descriptor :Introspector.getBeanInfo(A.class).getPropertyDescriptors()){
System.out.println("Getter method :" + descriptor.getReadMethod());
System.out.println("Return type : " + descriptor.getReadMethod().getReturnType());
Class<?> c=descriptor.getReadMethod().getReturnType();
}
}
Output :
Getter method :public final native java.lang.Class java.lang.Object.getClass()
Return type : class java.lang.Class
Getter method :public java.util.Date A.getDate()
Return type : class java.util.Date
Getter method :public java.lang.String A.getName()
Return type : class java.lang.String
Getter method :public java.lang.Integer A.getNumber()
Return type : class java.lang.Integer
Then, you can easily create a Field for each of those getters. For the generic type, it does not really make sense at runtime but it is still possible to use this in a code generator...