2013-11-25 59 views
0

的返回类型为查找(ID)方法,为什么系统始终坚持认为需要教练的返回类型,我想我已经声明, “入口”是指导教师。对于查找(ID)方法,为什么系统,总是坚持要求教师

// 1. TO DO 
/** findID(String) is passed an id and returns the 
* Instructor object in the Instructor arraylist having that 
* id or null if not found 
* @return 
*/ 

public Instructor findID (String id) { 
    for (Instructor entry:instList) { 
     if (entry.getId().equals(id) == true) { 
      return entry; 
     } else return null; 
    } 
} 
+0

是否'instList'集合有一个通用的类型? – Roman

回答

0

我相信,你instList列表声明为原料类型,即:

List instList = new ArrayList(); 

所以,让你的代码编译的一种方法,是用一个类型来声明instList

List<Instructor> instList = new ArrayList<Instructor>(); 

如果你不能做到这一点(即你从远程源获得这个集合),你可以将它转换为所需的类型:

for (Instructor entry: (List<Instructor>)instList) { 
    ... 
} 

最后,你可以施放检索到的对象,而不是铸造整个集合:

for (Object entry : instList) { 
    Object instructor = (Instructor)entry; 
    ... 
}