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??>