Во время выполнения моего кода я получаю предупреждение для моего кода, как показано ниже:
javac HashedDictionaryOpenAddressingLinear.java -Xlint
HashedDictionaryOpenAddressingLinear.java:54: warning: [rawtypes] found raw type: HashedDictionaryOpenAddressingLinear.TableEntry
TableEntry<K,V>[] temp = (TableEntry<K,V>[]) new TableEntry[tableSize];
^
missing type arguments for generic class HashedDictionaryOpenAddressingLinear<K,V>.TableEntry<S,T>
where S,T,K,V are type-variables:
S extends Object declared in class HashedDictionaryOpenAddressingLinear.TableEntry
T extends Object declared in class HashedDictionaryOpenAddressingLinear.TableEntry
K extends Object declared in class HashedDictionaryOpenAddressingLinear
V extends Object declared in class HashedDictionaryOpenAddressingLinear
HashedDictionaryOpenAddressingLinear.java:243: warning: [rawtypes] found raw type: HashedDictionaryOpenAddressingLinear.TableEntry
hashTable[index] = new TableEntry(key, value);
^
missing type arguments for generic class HashedDictionaryOpenAddressingLinear<K,V>.TableEntry<S,T>
where S,T,K,V are type-variables:
S extends Object declared in class HashedDictionaryOpenAddressingLinear.TableEntry
T extends Object declared in class HashedDictionaryOpenAddressingLinear.TableEntry
K extends Object declared in class HashedDictionaryOpenAddressingLinear
V extends Object declared in class HashedDictionaryOpenAddressingLinear
Фактический код для предупреждений показан ниже: - Фактический код для предупреждения в строке 54:
public HashedDictionaryOpenAddressingLinear(int initialCapacity)
{
checkCapacity(initialCapacity);
numberOfEntries = 0;
// Set up hash table: Initial size of hash table is same as
// initialCapacity if it is prime otherwise increase it until it is
// prime size
tableSize = getNextPrime(initialCapacity);
checkSize(tableSize); // Check for max array size
// The case is safe because the new array contains null entries
@SuppressWarnings("unchecked")
TableEntry<K,V>[] temp = (TableEntry<K,V>[]) new TableEntry[tableSize]; // LINE 54 CAUSING WARNING FOR RAWTYPE
hashTable = temp;
initialized = true;
} // end constructor
Фактический код для предупреждения в строке 243:
@Override
public V add(K key, V value)
{
checkInitialization();
if((key == null) || (value == null))
{
throw new IllegalArgumentException();
}
else
{
V oldValue; // Value to return
int index = getHashIndex(key);
index = probe(index, key); // Check for and resolve collision
// Assertion: index is within legal range for hashTable
assert (index >= 0) && (index < hashTable.length);
if((hashTable[index] == null) || hashTable[index].isRemoved())
{ // Key not found, so insert new entry
hashTable[index] = new TableEntry(key, value); // LINE 243 CAUSING WARNING FOR RAWTYPE
numberOfEntries++;
oldValue = null;
}
else
{ // Key found; get old value for return and then replace it
oldValue = hashTable[index].getValue();
hashTable[index].setValue(value);
} // end if
// Ensure that hash table is large enough for another add
if(isHashTableTooFull())
{
enlargeHashTable();
}
return oldValue;
} // end if
} // end add
Какие изменения я должен внести в код, чтобы он соответствовал текущему API и не получал эти предупреждения? Пожалуйста, дайте мне знать любые предложения.