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"
Try
GenericModel.class.isAssignableFrom(field.getType())
You have the test backwards.
GenericModel.class.isAssignableFrom(field.getType())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With