1

How would you expose type of implementing class of an object regardless of whether it's real object or proxy ?

Here is example of the problem https://github.com/AsyncHttpClient/async-http-client/issues/1523

I thought I could intercept getClass call in proxy but then I realized:

1) proxy intercepts only calls to interfaces defined as parameter to Proxy.newProxyInstance; 2) I can't override getClass in my interface because it's final.

I can of course add my own getImplementingClass to my interface and use it everywhere instead of instanceof but it looks hacky.

I can and know how to get class of invocation handler. But it (ReleasePermitOnComplete) is different from implementing class (WebSocketUpgradeHandler). Thus this question is more design question than simple question about how dynamic proxies work.

Ideas ?

expert
  • 29,290
  • 30
  • 110
  • 214
  • Why? The whole idea of proxy classes is that they *conceal* the implementation. – user207421 Feb 18 '18 at 08:54
  • @EJP I agree but `instanceof` has its valid use-cases. The question is how to continue using it regardless of whether it's proxy or not. – expert Feb 18 '18 at 09:31
  • Duplicate of https://stackoverflow.com/questions/3344299/how-do-i-get-the-underlying-type-of-a-proxy-object-in-java? – lexicore Feb 18 '18 at 11:04
  • @lexicore I updated my question earlier this morning explaining why it's not duplicate :) But yeah, it may appear so. – expert Feb 18 '18 at 13:40

0 Answers0