| Author |
Generic Java - Linked List
|
Timothy Leong
Ranch Hand
Joined: May 25, 2005
Posts: 55
|
|
dear all, I done the following LinkedList and Node classes. I have problem coding the sorting portion (the bold line). I keep getting cannot find symbol method compareTo(E) class: java.lang.object what should I do to make my coding works?? Thanks in advance [ September 22, 2005: Message edited by: Timothy Leong ]
|
 |
Timothy Leong
Ranch Hand
Joined: May 25, 2005
Posts: 55
|
|
by the way, is Parametric Polymorphism under Java Collections Framework?? Thanks
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
The getItem() method returns an E object, not a LLNode<E> object. The compareTo() method is not available in the E object. In any case, I wouldn't know how to fix it, as I don't know how the compareTo() method is supposed to work. It looks like all the LLNode<E> class' compareTo() method does is return a -2. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Timothy Leong
Ranch Hand
Joined: May 25, 2005
Posts: 55
|
|
hi guys, I have edited my codings public class BankDatabase extends LinkedList<Customer> { ..... } however I keep getting "Type parameter Customer is not within its bound" what's the problem here?? thanks [ September 22, 2005: Message edited by: Timothy Leong ]
|
 |
Timothy Leong
Ranch Hand
Joined: May 25, 2005
Posts: 55
|
|
up... any1 know wat's wrong with the codes?? Thank you
|
 |
Rick O'Shay
Ranch Hand
Joined: Sep 19, 2004
Posts: 531
|
|
You are not implementing comparable<T> on the node. I think you should reduce the clutter and get a tiny example working first. [ September 23, 2005: Message edited by: Rick O'Shay ]
|
 |
Timothy Leong
Ranch Hand
Joined: May 25, 2005
Posts: 55
|
|
i tried casting it using Comparator but still receive the same error. Do you mean i should compare with nodes instead of the object? I am trying to compare the E objects together and let them call their compareTo methods which I have already specified in their own classes [ September 24, 2005: Message edited by: Timothy Leong ] [ September 24, 2005: Message edited by: Timothy Leong ]
|
 |
Akshay Kiran
Ranch Hand
Joined: Aug 18, 2005
Posts: 220
|
|
Originally posted by Timothy Leong: hi guys, I have edited my codings public class BankDatabase extends LinkedList<Customer> { ..... } however I keep getting "Type parameter Customer is not within its bound" what's the problem here?? thanks [ September 22, 2005: Message edited by: Timothy Leong ]
This one is easy it should be public class BankDatabase<Customer> extends LinkedList<Customer> it says type parameter out of bounds because the Customer type is not avaiable to the BankDatabase. What you've done is just made a "raw" type extend a "generic" type while what you intended was "generic" type extending "generic" type. Hope that helps. (I have not looked into your first problem yet)
|
"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
|
 |
Akshay Kiran
Ranch Hand
Joined: Aug 18, 2005
Posts: 220
|
|
Originally posted by Timothy Leong: [ September 24, 2005: Message edited by: Timothy Leong ] [ September 24, 2005: Message edited by: Timothy Leong ]
Try this public <E extends Comparable<E>> void insert(E o) and get rid of that cast, I think that should do the job if it doesn;t work, try the case E temp= curr.getItem(); //this should not have any significant effect and in the worst, Comparable<?> temp = (Comparable<?> curr.getItem() //though the cast is unecessary.
|
 |
 |
|
|
subject: Generic Java - Linked List
|
|
|