• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic Java - Linked List

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by the way,

is Parametric Polymorphism under Java Collections Framework?? Thanks
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
up...


any1 know wat's wrong with the codes?? Thank you
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)
 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic