开发者

SplayTrees and a Dictionary

开发者 https://www.devze.com 2022-12-19 04:09 出处:网络
I\'m use a splaytree class as the data storage for the \"dictionary\". I have the following to deal with Integers, Objects, etc.:

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 mismatc开发者_JS百科h: 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?


You didn't make class Entry implement Comparable.

public class Entry<T> implements Comparable<T> {
    // ...
    public int compareTo(final T t) {
        // ...
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消