I have to write a utility method that can get the particular variable value from an Object, on evaluating some conditions.
Below are the requirements.
- if "name" is coming as type call "getName" to get the Value.
- If "subtype" is coming as type call "getSubType" to get the Subtype Value.
Current Solution:
public Object getFieldValue(String type, IDTO dto){
Method method = dto.getClass().getMethod("get"+createMethodName(type));
Object returnedObject = method.invoke(dto, null);
return returnedObject;
}
However, the operations are quite heavy and it is giving performance issues. Is there any alternative that can be chosen or any better way to do this.
Other points:
- Interface IDTO has all the getter setters declared only. No fields declared in that.
Aucun commentaire:
Enregistrer un commentaire