1.Does dynamic proxy instance subclass the target class?
The java doc says the proxy instance implements “a list of interfaces”, says nothing about subclassing, but through debugging, I saw that the proxy instance did inherit the target class properites.What does the “a list of interfaces ” mean? Can I exclude those interfaces implemented by target class ?
2.Can I invoke target class specific methods on a proxy instance?
3.
I think dynamic proxy is an interface methods invocation proxy but rather than a target class proxy, is that right (I am deeply infected by hibernate proxy object concept)?
If you’re talking about the
java.lang.reflect.Proxyclass: there’s no such thing as a “target class” in general.The proxy is constructed by specifying a list of interfaces that the proxy object will implement, and an invocation handler whose
invoke()method all method calls on the proxy will be forwarded to. The invocation handler can do anything with them, including forwarding them to a “target class” instance it holds a reference to.