title: Proxying a Java class with an internal class cast
body: <p>Here's a problem I am facing.</p>
  
  <p>I am writing a plugin. There is an interface called <em>SystemObject</em>, and a default getter. </p>
  
  <pre><code>public class MyPlugin extends Plugin {
          @override
          public SystemObject getSystemObject() {
                  return super.getSystemObject();
          } 
  }
  </code></pre>
  
  <p>SystemObject interface has a method called getScreenSize() which I would like to proxy or intercept. When I create a proxy class, or simply implement this SystemObject interface myself, I get a class cast exception.</p>
  
  <p>This is because the caller for getSystemObject (part of the plugin system) has this in their code (found via reverse-engineering):</p>
  
  <pre><code>private void foo() { 
       SystemObjectImpl impl = (SystemObjectImpl)plugin.getSystemObject(); 
  }
  </code></pre>
  
  <hr>
  
  <p>My question is: <strong>is there any way I can proxy calls on the SystemObject interface?</strong></p>
  
  <p>I tried implementing the interface and using java reflection proxy invocation to no avail. Unfortunately, I'm not responsible for running the java process, so I can't use an agent.</p>
  
  <p>Cheers!</p>