views:

40

answers:

2

I'm use a splaytree class as the data storage for the "dictionary".

I have the following to deal with Integers, Objects, etc.:

public class SplayTree<T extends Comparable<? super T>>

And I also have the following:

public class Entry<T> {
    public Entry(T word, T def){}
    ...
}

Which is what I'm using to add a word entry and its definition

But when I try to run some test data, for Ex:

SplayTree<Entry> tree = new SplayTree<Entry>();
tree.insert(new Entry("test", "test"));

I get the following error:

Bound mismatch: The type Entry is not a valid substitute for the bounded parameter > of the type SplayTree

Any idea to what I should do to fix this?

+2  A: 

You didn't make class Entry implement Comparable.

public class Entry<T> implements Comparable<T> {
    // ...
    public int compareTo(final T t) {
        // ...
    }
}
Pointy
Doesn't that need to have a method `compareTo` instead of `compare`?
Shawn
ooh right thanks - that's the sort of mistake I make 10000 times a day :-)
Pointy
A: 

Okay, so in that compareTo() method, I would need to compare the word to the final T t correct? Or what would be the best way to go about that?

Shawn
You'd have tom compare the Entry. In your case the word might indeed be best for ordering. You could use the String.compareTo method, or the compareToIgnoreCase, whatever you like best. So the Entries compareTo would do if (t != null }The null checks are optional; if you know for sure you won't have null entries or null words then don't check :)
extraneon
I do that and I still get the same error from my original question.
Shawn