我试图创建一个数组条目< K,V>元素。有了这段代码,我得到了java.lang.ClassCastException。我怎样才能解决这个问题?java.lang.ClassCastException Object to HashTable.Entry
public class HashTable<K, V> {
private final int INITIAL_SIZE = 128;
private Entry<K, V>[] table;
public HashTable() {
table = (Entry<K,V>[]) new Object[INITIAL_SIZE];
}
static class Entry<K, V> {
// Here comes constructor and other stuff
}
}
您无法从对象数组创建映射。 – Nicolas
@Nicolas我想创建一个数组,我将在那里存储条目。这是不可能的吗? –
tarexme
那么你可以这样做'List> list = new ArrayList <>()' –
Nicolas