动态代理:
public interface Qingke {
void qk();
}
public class dsz implements Qingke{
public void qk() {
System.out.print("dsz qk");
}
}
public class Secretary implements InvocationHandler {
private Object pro;
private dsz dsz;
public Object bind(Object deledate){
this.pro = deledate;
return Proxy.newProxyInstance(deledate.getClass().getClassLoader(), deledate.getClass().getInterfaces(), this);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
method.invoke(pro, args);
return null;
}
}
test:
public class ProxyTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
dsz dsz1 = new dsz();
Qingke se = (Qingke)new Secretary().bind(dsz1);
se.qk();
}
}