package poxy;
import java
import java
import java
/**
* Simple Dynamic Proxy
*
* @author daniel zhou
*/
public class SimpleDynamicProxy {
/**
* @param args
*/
public static void main(String[] args) {
//generate a hanlder
ProxyHanlder hanlder=new ProxyHanlder();
/*
* register instance to hanlder
*/
Dog dogProxy=(Dog) hanlder
@Override
public String eat(String food) {
return
}
});
//do method by proxy
String result = dogProxy
//take a look
System
}
}
//Proxy Handler
class ProxyHanlder implements InvocationHandler{
//container
Object obj = new Object();
public Object generateProxyHanlder(Object obj) {
//store it
this
//return interface proxy
return Proxy
obj
this);
}
@Override
public Object invoke(Object proxy
throws Throwable {
Object result=null;
result=method
return result;
}
}
//interface
interface Dog{
String eat(String food);
}
本文出自
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27626.html