views:

26

answers:

3

Lets say i have a Proxy to an object, can I somehow get access to the object via reflection or other technique ?

A: 

What do you mean by "Proxy to an object"? If you mean the invocation handler of a java.lang.reflect.Proxy instance:

InvocationHandler handler = Proxy.getInvocationHandler(proxy);
Michael Borgwardt
+1  A: 

No, as a Proxy is not even itself a "true" object. From the javadoc, you can see that the only object you can easily access is the invocation handler. Once this handler is reached, it's a matter of implementation :

  • you may encounter n invocation handler that keeps a reference to proxied object (as an example for kind of a decorator)
  • but you can also have no other reference (as an example, when implementing the Null object pattern using proxy).
Riduidel
A: 

If you have a proxy to an object you can use the proxy to access the object.

proxy - An interface for a service, especially for one that is remote, resource-intensive, or otherwise difficult to use directly. (wiktionary)

emory