I am currently despairing over a supposedly simple task.
protected Entry<K, V>[] entries;
public V getOrThrow(K k) throws UnknownKeyException
{
for(Entry<K, V> i : entries)
{
if(i.getValue() != null)
{
if(i.getKey().equals(k))
{
return i.getValue();
}
else throw new UnknownKeyException();
}
else throw new UnknownKeyException();
}
}
This method should check whether a value exists, then whether the associated key matches the passed parameter and then return the value. Otherwise, an exception is to be thrown. The value is of the type V. Now I get the error: "This method must return a result of type V". So I suppose not every case of the if statement is covered. Is this because of the exceptions? Are exceptions even legal else statements? Or what else could it be? Thanks a lot in advance!
Aucun commentaire:
Enregistrer un commentaire