Generic Java, type not bounded
I have declared LinkedList<Customer> LL = new LinkList<Customer> (); in my main class.
Under my class Customer, I have a compareTo method too.
I get an error on Type parameter customer is not within its bound.
I believe the problem lies with the bold portion of the code which sorts the node.
Can somebody guide me please? Thank in advance.
interface Comparable<A>
{
public int compareTo(A that);
}
class LinkedList<E extends Comparable<E>>
// Representation of a linked list of objects of type E.
{
private int numItems; // number of elements in list
private LLNode<E> head; // pointer to head of list
public LinkedList()
// Default constructor - create new empty linked list.
{
numItems = 0;
head = null;
}
// Accessor methods.
public LLNode<E> getHead() { return head; }
public int size() { return numItems; }
public boolean isEmpty() { return (head == null); }
public void setHead (LLNode<E> newHead)
{
head = newHead;
}
public void setNumItems (int newNumItems)
{
numItems = newNumItems;
}
public void insert(E var)
{
LLNode<E> newNode = new LLNode<E> (var);
setNumItems(size()+1);
if(isEmpty())
setHead(newNode);
else
{ LLNode<E> prev=null;
for(LLNode<E> curr=getHead(); curr != null; prev = curr, curr=curr.getNext())
{
E tmpItem = curr.getItem();
if(tmpItem.compareTo(var) > 0)
{
// insert before curr node
newNode.setNext (curr);
if (prev != null)
prev.setNext (newNode);
else
setHead (newNode);
return;
}
}
// insert at end of list
prev.setNext (newNode);
}
}
}

