title: Restrict types in Java for use in a List
body: <p>How can I pass a <code>List&lt;T&gt;</code> with a set of certain allowed types I did not declare to a method.</p>
  
  <p>E.g. Restrict types to Integer, Boolean and <code>String</code>:</p>
  
  <pre><code>// Pseudo code
  public void method(List&lt;Integer OR Boolean OR String&gt; myList);
  </code></pre>
  
  <hr>
  
  <p>If I use <code>List&lt;Object&gt;</code> I can put everything into that list:</p>
  
  <pre><code>public void method(List&lt;Object&gt; myList);
  </code></pre>
  
  <p>If I use List I can put all instances of <code>Parent</code> and its subclasses into that list:</p>
  
  <pre><code>public void method(List&lt;Parent&gt; myList);
  </code></pre>
  
  <p>That would be enough if I am the one who declares those subclasses (<code>AllowedTypeA extends Parent</code>). But what can I do when I'm not the owner of the classes I want to use (I cannot make <code>Integer</code> extend <code>Parent</code>)?</p>