title: Java generic arguments
body: <p>Going back over my basic ADT stuff here to revise for an interview, and trying to kill two birds with one stone by learning Java while I am. Attempting to write a simple algorithm for a merge sort with a generic linked list ( which I am creating myself). It's proving to be far more difficult than I had first imagined ! Can anyone help me out please ? I will start out working on the basics and will update this post as I get further in.</p>
  
  <p>My code for the generic linked list is as follows :</p>
  
  <pre><code> public class NodeList&lt;T extends Comparable&lt;T&gt; &gt; {
    private T head;
    public NodeList&lt;T&gt; tail;
    public NodeList( T item, NodeList&lt;T&gt; list ) {
      head = item;
      tail = list;
    } 
  
  }
  </code></pre>
  
  <p>I am trying to access this class in another class I have made, which is as follows :</p>
  
  <pre><code>    public class MyList&lt;T extends Comparable&lt;T&gt;&gt; {
  
    private NodeList&lt;T&gt; nodes;
    private static int size;
    public MyList( ) { 
      nodes = null; 
    }
  
    public MyList(T[] array ){
      for( T item : array ) {
        nodes = new NodeList&lt;T&gt;(item, nodes); 
      }
      size = array.length;
    }
  
  
    public void add( T item ) { 
      nodes = new NodeList&lt;T&gt;( item, nodes ); 
      size++;
    }
  
  
    public void addEnd( T item ) {
      NodeList&lt;T&gt; temp = nodes;
      while ( temp == null || temp.tail != null) {
        temp = temp.tail;
      }
      size++;
      temp.tail = new NodeList&lt;T&gt; ( item, null);
    }
  </code></pre>
  
  <p>I believe, so far, everything to be correct up until the add and addEnd methods, which should add a generic to the start of the list and end of the list respectively. </p>
  
  <p>My code continues with :</p>
  
  <pre><code> public static &lt;S extends Comparable&lt;S&gt;&gt;
      MyList&lt;S&gt; sort( MyList&lt;S&gt; list ) {
  
      if ( size &gt; 1 ) {
  
        MyList&lt;S&gt; left  = leftHalf( list );
        MyList&lt;S&gt; right = rightHalf( list );
        list = merge( left, right );
      }
  
      return list;
    }
  
    private static &lt;S extends Comparable&lt;S&gt;&gt;
      MyList&lt;S&gt; merge( MyList&lt;S&gt; left, MyList&lt;S&gt; right ) {
  
    }
  
    private static &lt;S extends Comparable&lt;S&gt;&gt;
      MyList&lt;S&gt; leftHalf( MyList&lt;S&gt; list ) {
      MyList &lt;S&gt; leftSide = new MyList();
      int middle;
      if(size % 2 == 1) {
       middle = size +1;
      } else {
       middle = size; 
      }
      for ( int countToMiddle = 0; countToMiddle &lt; middle ; countToMiddle++ ) {
        leftSide.addEnd(nodes);
      }
  
  
      // return elements from 0 .. list.size() / 2
    }
  </code></pre>
  
  <p>And I get the error:</p>
  
  <blockquote>
    <p>addEnd(S) in MyList cannot be applied to (NodeList)</p>
  </blockquote>
  
  <p>which occurs when I run</p>
  
  <blockquote>
    <p>leftSide.addEnd(nodes);</p>
  </blockquote>
  
  <p>Can anyone see a reason for this/ tell me if I am correct up to this point of my work ? Thanks so much again!</p>