title: How to declared method in Java generically, operating on interface of several subtypes?
body: <p>I have the following</p>
  
  <p>Interface:</p>
  
  <pre><code>public interface General {...}
  </code></pre>
  
  <p>Then, couple of implementations of that interface:</p>
  
  <pre><code>public class Specific1 implements General {...}
  
  public class Specific2 implements General {...}
  </code></pre>
  
  <p>Then, I have a utility method that needs to combine 2 lists of either:</p>
  
  <pre><code>List&lt;Specific1&gt; list1 = ...;
  List&lt;Specific1&gt; list2 = ...;
  List&lt;Specific1&gt; mergedList = mergeLists(list1, list2);
  </code></pre>
  
  <p>OR:</p>
  
  <pre><code>List&lt;Specific2&gt; list1 = ...;
  List&lt;Specific2&gt; list2 = ...;
  List&lt;Specific2&gt; mergedList = mergeLists(list1, list2);
  </code></pre>
  
  <p>I then have to perform something like this: <code>pojo.setSpecific1List(mergedList)</code>, which doesn't allow me to declare my <code>mergedList</code> as <code>List&lt;General&gt; mergedList</code>.</p>
  
  <p>Question is: how do I declared the <code>mergeLists</code> method generically? Is it possible given what I need to do with the returned value?</p>