title: Generic collection as a Java method argument
body: <p>Is there any way to make this work in Java?</p>
  
  <pre><code> public static void change(List&lt;? extends Object&gt; list, int pos1, int pos2) {
    Object obj = list.get(pos1);
    list.set(pos1, list.get(pos2));
    list.set(pos2, obj);
   }
  </code></pre>
  
  <p>The only way I've successfully avoided warnings and errors is this:</p>
  
  <pre><code> public static &lt;T&gt; T change(List&lt;T&gt; list, int pos1, int pos2) {
    T obj = list.get(pos1);
    list.set(pos1, list.get(pos2));
    list.set(pos2, obj);
    return obj;
   }
  </code></pre>
  
  <p>but I don't like to be forced to return a value.</p>