title: Restricting the class to accept only any one interface implementations but not mixed?
body: <p>I have below classes and interfaces.</p>
  
  <p>SuperInterface.java</p>
  
  <pre><code>public interface SuperInterface{/*some logic*/}
  </code></pre>
  
  <p>SubOneInterface.java</p>
  
  <pre><code>public interface SubOneInterface extends SuperInterface{/*some logic*/}
  </code></pre>
  
  <p>SubTwoInterface.java</p>
  
  <pre><code>public interface SubTwoInterface extends SuperInterface{/*some logic*/}
  </code></pre>
  
  <p>One.java</p>
  
  <pre><code>public class One{/*some logic*/}
  </code></pre>
  
  <p>Two.java</p>
  
  <pre><code>public class Two{/*some logic*/}
  </code></pre>
  
  <p>SubOne.java</p>
  
  <pre><code>public class SubOne extends One implements SubOneInterface{/*some logic*/}
  </code></pre>
  
  <p>AnotherSubOne.java</p>
  
  <pre><code>public class AnotherSubOne extends One implements SubTwoInterface{/*some logic*/}
  </code></pre>
  
  <p>SubTwo.java</p>
  
  <pre><code>public class SubTwo extends Two implements SubOneInterface{/*some logic*/}
  </code></pre>
  
  <p>AnotherSubTwo.java</p>
  
  <pre><code>public class AnotherSubTwo extends Two implements SubTwoInterface{/*some logic*/}
  </code></pre>
  
  <p>Now  i have to write a class which will hold the implementation classes of both SubOneInterface and SubTwoInterface.</p>
  
  <pre><code>public class ClassesHolder{
  
   private List&lt;One&gt; one;
  private List&lt;Two&gt; two;
  
  //setters and getters
  
  }
  </code></pre>
  
  <p>Now <code>ClassesHolder</code> should accept all the objects(<strong>sub classes of One and Two</strong>) which implements either <code>SubOneInterface</code> or <code>SubTwoInterface</code> But not mix of both interfaces.</p>
  
  <p>IF they try to populate the lists with mixed interface implementations then exception should be thrown.</p>
  
  <p>How can i do that?</p>