我正在编写一个方法来返回数组中的特定记录,但是它会引发两个错误,我不确定如何修复它。谁能解释我做错了什么?
public String find(String searchName)
{ // ERROR - MISSING RETURN STATEMENT
Iterator<TelEntry> iterator = Directory.entries.iterator();
boolean hasFound = false;
while (iterator.hasNext())
{
TelEntry entry = iterator.next();
if (entry.name.equalsIgnoreCase(searchName)) {
return entry.name + entry.telNo;
hasFound = true; // ERROR UNREACHABLE STATEMENT
}
}
if (hasFound==false)
{
System.out.println("sorry, there is noone by that name in the Directory. Check your spelling and try again");
}
}
谁能解释我做错了什么?