Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

type parameter X is not within its bound

Thread view: 
Mark - 03 Nov 2006 08:31 GMT
I get the following error, and I'm not sure why.

EKT.java:7: type parameter WordPair is not within its bound
    static BST<WordPair> tree = new BST<WordPair>();
                  ^
EKT.java:7: type parameter WordPair is not within its bound
    static BST<WordPair> tree = new BST<WordPair>();
                                           ^
2 errors
> Terminated with exit code 1.

BST is declared as: class BST<T extends Comparable<? super T>>
and WordPair is declared as: class WordPair implements Comparable

Let me know if you need more information.

WordPair implements Comparable, and BST requires a Comparable class.
I'm not sure what the problem is.  BST<Integer> works fine.
Mark - 03 Nov 2006 09:04 GMT
> I get the following error, and I'm not sure why.
>
[quoted text clipped - 14 lines]
> WordPair implements Comparable, and BST requires a Comparable class.
> I'm not sure what the problem is.  BST<Integer> works fine.

I forget how I came up with this solution... it hurt my head just
thinking about it... but here's what I came up with (it compiles now)

Just had to change WordPair's declaration to: class WordPair implements
Comparable<WordPair>
and then change my compareTo function to
public int compareTo(WordPair wp)
instead of taking an object... which also means that I no longer have
to cast it to a wordpair!  Two birds with one stone.
Hendrik Maryns - 03 Nov 2006 13:10 GMT
Mark schreef:
>> I get the following error, and I'm not sure why.
>>
[quoted text clipped - 23 lines]
> instead of taking an object... which also means that I no longer have
> to cast it to a wordpair!  Two birds with one stone.

Indeed, as I mentioned in my other post, Comparable is parameterised.
Once you start off with generics, you have to use parameters on /all/
generic classes.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
hiwa - 03 Nov 2006 09:41 GMT
> I get the following error, and I'm not sure why.
>
[quoted text clipped - 14 lines]
> WordPair implements Comparable, and BST requires a Comparable class.
> I'm not sure what the problem is.  BST<Integer> works fine.
WordPair implements Comparable<WHAT??>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.