type parameter X is not within its bound

M

Mark

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.
 
M

Mark

Mark said:
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

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.

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.
 
H

hiwa

Mark said:
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

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.
WordPair implements Comparable<WHAT??>
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mark schreef:
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.

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFFSzHFe+7xMGD3itQRAi19AJ9WOtiAr69ix+uY50Qyi6E1p3DfZACeNCua
R0rwWV8qzJIqV/uaXyHpPmY=
=Bmt0
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,099
Members
48,773
Latest member
Kaybee

Latest Threads

Top