Use InvocationHandler and Proxy without using interface [duplicate]

二次信任 提交于 2019-12-25 06:39:55

问题


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.



来源:https://stackoverflow.com/questions/10765061/use-invocationhandler-and-proxy-without-using-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!