Java反射机制有哪些应用?
目标:用一个代理类实现两个相似类的调用
1。两个相似类
Man类
Women类:
代理类:
package Reflect;
import java。lang。reflect。
Method;
public class Person {
//代理类
private Object target; //目标对象
private String methodName; //目标方法
private Object[] params;
//参数数组
private Method method;
public Object getTarget() {
return target;
}
public void setTarget(Object target) {
this。
target = target;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this。
methodName = methodName;
}
public Object[] getParams() {
return params;
}。 。