public class Table<Key extends Comparable<Key>, Value> {
/*
* The purpose of entry is to glue together a key and a value
*
* The class that we use for Key has to implement comparable
* */
private class Entry<Key extends Comparable<Key>, Value> implements Comparable<Entry>
{
Key key;
Value value;
public Entry(Key k, Value v)
{
key = k;
value = v;
}
public int compareTo(Entry<Key,Value> entry)
{
return key.compareTo(entry.key);
}
}
private BST<Table.Entry<Key, Value>> tree = new BST<Table.Entry<Key, Value>>();
//must supply public methods for the three operations
public Value lookUp(Key key)
{
Entry<Key, Value> e = new Entry<Key, Value>(key, null);
return tree.search(e).value;
}
public boolean insert(Key k, Value v)
{
return tree.insert(new Entry<Key, Value>(k, v));
}
public boolean delete(Key k)
{
//we haven't written a delete method for bst yet.
return tree.delete(new Entry(k, null));
}
}
以上是我的教授在课堂上讨论的表抽象数据类型的类声明。我一直在试图弄清楚为什么 Java 会给我以下错误消息
在原始类型上给出的类型参数
当我在这里声明我的变量时
private BST<Table.Entry<Key, Value>> tree = new BST<Table.Entry<Key, Value>>();
java中的原始类型是什么?我们已经讨论过编写泛型类。与此有关吗?