我正在使用AOP来查找实例变量在设置之前和之后的值。因此,我拦截所有的setxxx
方法,并尝试在之前和之后执行getxxx
。
//actual instance
Object target = joinPoint.getTarget();
//Type of the instance
Class objectClass = target.getClass();
我希望能够调用一个名为“getFirstName()”的字符串,实际上它是实例(目标)上的一个方法名称。我该如何做到这一点?
目前,我可以执行以下操作:
if (target instanceof User) {
instanceVarCurrentValue = ((User) target).getFirstName();
}
但我无法检查项目中所有对象的实例,对于每个类,我都必须检查所有属性。