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条回答
我命由我不由天
2楼-- · 2019-09-15 04:33

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

查看更多
登录 后发表回答