title: Java - Generics; Is it usefull to parameterize a method if you want to swap 2 Items of an object?
body: <p>The following code alows to swap 2 Items of an Object :</p>
  
  <pre><code>public class Box&lt;F, S&gt; {
      F first;
      S second;   
  
      //Method to swap
      public static &lt;F&gt; void swapItems(Box&lt;F,F&gt; box){
  
          F temp = box.first;
          box.first = box.second;
          box.second = temp;
      }
  }
  
  //The method could also be implemented like this:
  
      void swapItems() {
  
          F tmp1 = first;
          S tmp2 = second;
          first = (F) tmp2;
          second = (S) tmp1;
      }
  </code></pre>
  
  <p>What is the advantage of the generic code? I just don't get it. 
  Could sombody explain this to me? Might the generic one be useful if i call this method on 2 objects?</p>