This week's book giveaway is in the
Agile and other Processes
forum.
We're giving away four copies of
The Mikado Method
and have Ola Ellnestam and Daniel Brolund on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Generic Java, Type not bounded
Timothy Leong
Ranch Hand
Joined: May 25, 2005
Posts: 55
posted
Sep 23, 2005 14:13:00
0
Dear guys,
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(); [B]if(tmpItem.compareTo(var) > 0) [/B] { // 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); } } }
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17228
1
I like...
posted
Sep 23, 2005 15:22:00
0
Duplicate thread. Check in the Java In General (Intermediate)
Mark
Perfect World Programming, LLC
-
Two Laptop Bag
-
Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
http://aspose.com/file-tools
subject: Generic Java, Type not bounded
Similar Threads
Object Comparable
Generic Java - Linked List
Generic Java
insertion of data
Linked List Sorting Problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter