0
我與哈希映射工作,我宣佈水桶從SLLNode
類型的數組保存MapEntry
對象:努力理解對象的聲明代碼
private SLLNode<MapEntry<K, E>>[] buckets;
現在,我不明白,在構造函數的代碼:
buckets = (SLLNode<MapEntry<K, E>>[]) new SLLNode[m]; //where m is int, and it is
// the size of the array.
我不明白這個問題,以及:
public SLLNode<MapEntry<K,E>> search(K targetKey) {
int b = hash(targetKey);
for (SLLNode<MapEntry<K,E>> curr = buckets[b]; curr != null; curr =
curr.succ) {
if (targetKey.equals(((MapEntry<K, E>) curr.element).key))
return curr;
if (targetKey.equals(((MapEntry<K, E>) curr.element).key))
return curr;
}
return null;
準確地說,我不明白如何將(K targetKey)
轉換爲(MapEntry<K,E>)
並將其用於equals方法的邏輯。
'buckets =(SLLNode> [])new SLLNode [m];' - 哪一部分讓您感到困惑?你能指出你不明白的具體語法,或者可能是你認爲這不起作用的具體原因嗎? –
user2357112
我不明白爲什麼(SLLNode> [])在新的SLLNode [m]之前使用。我一直都在使用它,但我不知道它到底是什麼。通常我已經聲明瞭如下對象:Object O = new Object(「something」) –
Mario