title: Can a java method return value depending upon condition?
body: <p>I have a <code>ICoreClient</code> interface and <code>AClient</code> and <code>BClient</code> classes implements this.</p>
  
  <p><code>ICoreClient</code> is exposed for users. </p>
  
  <p>I need to add a new method in <code>ICoreClient</code> interface. So, it needs to be implemented in both clients. I can not make this method generic as it has completely different signature but similar functionalities. </p>
  
  <p>I have 2 interfaces <code>xx</code> and <code>yy</code></p>
  
  <p><code>ClientA</code> implements <code>xx</code> and <code>ClientB</code> implements <code>yy</code></p>
  
  <p>So, I decided to add a new <code>testMethod</code> in <code>ICoreClient</code> that will provide me the instance of <code>xx</code> or <code>yy</code> depending upon clients.</p>
  
  <p>I want to return the instance of these interfaces from a single method depending upon condition. </p>
  
  <p><strong>In <code>ClientA</code>:</strong></p>
  
  <pre><code>public xx testMethod(){
    return instanceof xx;
  }
  </code></pre>
  
  <p><strong>In <code>ClientB</code>:</strong></p>
  
  <pre><code>public yy testMethod(){
    return instanceof yy;
  }
  </code></pre>
  
  <p><strong>What should I write in <code>ICoreClient</code> interface?</strong></p>
  
  <pre><code>public zz testMethod()
  </code></pre>
  
  <p>I tried putting a <strong>dummy interface</strong> <code>zz</code> (acting as a common supertype) both <code>xx</code> and <code>yy</code> are implementing this. But still not able to expose methods of <code>xx</code> and <code>yy</code> in their respective clients as finally it got typecasted in <code>zz</code>.</p>
  
  <p>Is there any known approach for this kind of scenario?     </p>
  
  <p><strong>Edit</strong>: If I make return type <code>Object</code>, method of these interfaces are not exposed. Although, Object contains the instance of <code>xx</code> or <code>yy</code>, </p>
  
  <p>User still needs to cast it to (<code>xx</code> or <code>yy</code> how will user know?) for using the methods in the interface.. I want to expose the methods of the <code>ClientX</code> without having to cast to <code>ClientA</code> or <code>ClientB</code>...</p>