I need to do a common action on data members of a certain type (Attachment
) declared not just in this Form
but inherited from super-classes of this Form
.
If I were to use Java reflection head-on I would have to iterate through getSuperclass()
until I hit a NULL superclass, which is not desirable.
My understanding is, Spring provides a ReflectionUtils method for that:
ReflectionUtils.doWithFields(Attachment.class, new FieldCallback() {
@Override
public void doWith (Field field) throws IllegalArgumentException, IllegalAccessException
{
// ... do action on this field
}
}
But this iterates over each field in the Attachment object at a time without knowing what the other fields are. Is there a way to get the object I'm working with as a whole?
My task is to set a certain Field to a certain string if another field in this object is NULL. So I have to look at the other fields at the same time.
I'm almost wondering, isn't there a similar method with an Object callback?
Aucun commentaire:
Enregistrer un commentaire