title: Swap method for quicksort in java
body: <p>Could anyone help me figure out this swap method that is a part of a larger quick sort program? It is supposed to take an array and two integers and swap the index positions indicated by the integers.</p>
  
  <pre><code>private static &lt;T extends Comparable&lt;T&gt;&gt; int partition(T[] table, int first, int last) {
      T pivot = table[first];
      int up = first;
      int down = last;
  
      do {
          while ((up &lt; last) &amp;&amp; (pivot.compareTo(table[up]) &gt;= 0)) {
              up++;
          }
          while (pivot.compareTo(table[down]) &lt; 0) {
              down--;
          }
          if (up &lt; down) {
              swap(table, up, down);
          } 
      }
  
      while (up &lt; down);
      swap(table, first, down);
      return down;
  }
  </code></pre>
  
  <p>The swap method is currently undefined and I am not sure how to get it working. I have tried writing the method:</p>
  
  <pre><code>void swap(T[] array, int a, int b) {
      T temp = array[a];
      array[a] = array[b];
      array[b] = temp;
  }
  </code></pre>
  
  <p>However I keep getting the error that T cannot resolve to a type. But when I try to change the type to int the method doesn't work where it is called above.</p>