I'm pretty confused on dynamic proxies. I understand that I need a ProxyCreator class that will have a interfaceArray va开发者_C百科riable. I am just not sure how I would go about creating an interface arrau. Also, can I get a simple explanation for how to do a dynamic proxy. Thanks again!
This way:
Closeable c = (Closeable) java.lang.reflect.Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class[]{ Closeable.class },
new MyHandler(obj));
// works! by MyHandler is called instead.
c.close();
So the required interfaces are passed as an array of classes, and MyHandler is InvocationHanlder, taking delegate object obj
as a parameter (if needed).
It all described here.
精彩评论