I need to check if an instance of the reflection Field type, as retrieved by Field.getType() is an instance of another class that extends a specific class, GenericModel.
I’m trying something as in the following pseudo code snippet:
if(field.getType() "is_a_superclass_of" GenericModel) {
... then do something with it
}
How do I do this?
When I try something like:
field.getType().isAssignableFrom(Language.class)
I get a result, true, which means it is of the Language class, which extends GenericModel. However;
field.getType().isAssignableFrom(GenericModel.class)
returns false?
field.getType() == "za.co.company.package.model.Language"
You have the test backwards.