开发者

How do you get an interface array (Dynamic Proxy)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜