title: Adding interface to existing Object
body: <p>I have a third party library which has a bunch of interfaces and builders to construct objects which implement the interfaces.  These constructed objects are then passed into containers.  I then have an interface in my application which I want to add an implementation of to an object returned from the builder.</p>
  
  <p>Third party</p>
  
  <pre><code>interface ThirdParty1 { ... }
  interface ThirdParty2 { ... }
  class Builder {
    ...
    public ThirdParty1 build() { ... }
  }
  class ThirdPartyContainer {
    void append(ThirdParty1 toAdd) { ... }
    ThirdParty1 take() { ... }
  }
  </code></pre>
  
  <p>My application</p>
  
  <pre><code>interface MyInterface { ... }
  class MainBody {
    ThirdPartyContainer queue;
  
    MainBody() {
      ThirdParty1 foo = new Builder().build();
      // something to add implementation of MyInterface to foo 
      queue.append(foo);
    }
  
    void calledLater() {
      ThirdParty1 bar = queue.take();
      if (bar instanceof MyInterface) {
        // do something
      } else if (bar instanceof ThirdParty2) {
        // do something else
      }
    }
  }
  </code></pre>
  
  <p>I know I could build a wrapper class that implemented ThirdParty1 and MyInterface and took an instance of ThirdParty which all calls where forwarded to.  However this means that if Builder.build returns something that is an implementation of ThirdParty1 and ThirdParty2 the ThirdParty2 implementation would be lost by the wrapper.</p>
  
  <p>I expect what I am after is not possible, but being fairly new to Java and all the Magic that can be done I wasn't certain.</p>