这玩意没啥意思。静态和动态,区别点,静态要操作成员方法得一一设置,动态就method动态玩。具体看代码。个人这模式感觉是套路,想不出啥所以然。静态的代码省了。aop用了就是动态。动态应该基于反射。
interface zz{
public void doSomething();
}
public class XX implements zz{
public void doSomething(){
System.out.println("aaaaaaa");
}
}
public class move implements java.lang.reflect.InvocationHandler{
public zz xx;
public move(zz xx){
this.xx = xx;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
System.out.println("aaaaaaaaabbbbbbbbbb");
method.invoke(this.xx, args);
return null;
}
}
public static void main(String[] args) throws Exception {
zz a = new test().new XX();
move move= new test().new move(a);
zz yy = (zz) Proxy.newProxyInstance(XX.class.getClassLoader(), new Class[]{zz.class}, move);
yy.doSomething();
}