Use InvocationHandler and Proxy without using inte

2019-09-15 03:42发布

问题:

Possible Duplicate:
Dynamic proxy for concrete classes

Once I create a InvocationHandler implementation, I can use it with Proxy.newProxyInstance function to get a object behaving differently. In this case, I have to create a interface and its implementation class to use the Proxy.newProxyInstance function:

MyInterface objDest = Proxy.newProxyInstance(MyInterfaceImpl.class.getClassLoader(),   
        MyInterfaceImpl.class.getInterfaces(),   
        new MyInvocationHandler(new MyInterfaceImpl()));  

Is it possible to do the same task directly using a simple class without interface?

回答1:

You should use CGLIB to create a dynamic proxy on a concrete class.