0

I'm pretty confused on dynamic proxies. I understand that I need a ProxyCreator class that will have a interfaceArray variable. 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!

thunderousNinja
  • 3,510
  • 9
  • 37
  • 49

1 Answers1

1

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.

Vladimir Dyuzhev
  • 18,130
  • 10
  • 48
  • 62