I tried using the Sun code posted on the proxy usage page , and I tried using DebugProxy to print which method is being called. The fact is that there must be an argument for the object for which I am creating a proxy server. If I try to create a proxy with an argument for the constructor, I get the following error:
Exception in thread "main" java.lang.ClassCastException: $ Proxy0 cannot be cast to myPackage.myClass
I created a proxy server as follows:
MyClass mc = (MyClass) DebugProxy.newInstance(new MyClass(props));
How to instantiate a proxy and still call the right constructor?
source
share