title: error in this java program?
body: <p>I am trying to create a generic class for linked list in java and I am facing some errors which I am not able to debug.</p>
  
  <p>Code:</p>
  
  <pre><code>class node&lt;T&gt;
  {
      T value;
      node&lt;T&gt; next;
  }
  class LinkedList&lt;T&gt;
  {
      static node&lt;T&gt; head,last;
      static int no;
      node&lt;T&gt; current=new node&lt;T&gt;();
  
      public &lt;T&gt; void add(T x)
      {
          this.current.value=x;
          this.current.next=null;
          last.next=this.current;
          last=this.current;
          if(no==0)
              head=this.current;
          no++;
      }
      public &lt;T&gt; T remove()
      {
  
          node&lt;T&gt; y=head;
          while(y.next.next!=null)
          {
              y=y.next;
          }
          T z =y.next.value;
          y.next=null;
          last=y;
          return z;   
      }
  
  }
  </code></pre>
  
  <p>I don't have much experience with generics. This is the error I am getting:</p>
  
  <pre><code>linkedlist.java:14: error: incompatible types
          this.current.value=x;
                             ^
    required: T#2
    found:    T#1
    where T#1,T#2 are type-variables:
      T#1 extends Object declared in method &lt;T#1&gt;add(T#1)
      T#2 extends Object declared in class LinkedList
  linkedlist.java:25: error: incompatible types
          node&lt;T&gt; y=head;
                    ^
    required: node&lt;T#2&gt;
    found:    node&lt;T#1&gt;
    where T#1,T#2 are type-variables:
      T#1 extends Object declared in class LinkedList
      T#2 extends Object declared in method &lt;T#2&gt;remove()
  linkedlist.java:32: error: incompatible types
          last=y;
               ^
    required: node&lt;T#2&gt;
    found:    node&lt;T#1&gt;
    where T#1,T#2 are type-variables:
      T#1 extends Object declared in method &lt;T#1&gt;remove()
      T#2 extends Object declared in class LinkedList
  3 errors
  </code></pre>
  
  <p>I know the error is due to the fact that T can be of different types in this cases but I don't know how to correct it.</p>