課程
/后端開(kāi)發(fā)
/Java
/Java入門(mén)第三季
遍歷學(xué)生對(duì)象stu課程時(shí)為啥會(huì)報(bào)錯(cuò)呀?
2018-10-24
源自:Java入門(mén)第三季 4-11
正在回答
private?Set<Courses>?courses; public?Set<Courses>?getCourses()?{ return?courses; } public?void?setCourses(Set<Courses>?courses)?{ this.courses?=?courses; } //利用foreach遍歷student中選擇的課程 public?void?travelStudent(Students?student)?{ for(Courses?course:student.getCourses())?{ System.out.println("course:"+course.getId()+"?,?"+course.getName()); } }
構(gòu)造Student類的時(shí)候,需要進(jìn)行泛型
private?Set<Courses>?courses; public?Set<Courses>?getCourses()?{ return?courses; } public?void?setCourses(Set<Courses>?courses)?{ this.courses?=?courses; } //利用foreach遍歷student中選擇的課程 public?void?travelStudent(Students?student)?{ for(Courses?course:student.getCourses())?{ System.out.println("course:"+course.getId()+"?,?"+course.getName()); } } //用于創(chuàng)建新的學(xué)生 public?Students(String?id,String?name)?{ this.id?=?id; this.name?=?name; this.courses?=?new?HashSet();//位于util.HashSet類中,是Set接口下的一個(gè)重要類 ?????????????????????????????//對(duì)courses進(jìn)行實(shí)例化 }
沒(méi)泛型
沒(méi)有導(dǎo)包
慕雪1536570 提問(wèn)者
舉報(bào)
Java中你必須懂得常用技能,不容錯(cuò)過(guò)的精彩,快來(lái)加入吧
1 回答map如何遍歷
4 回答如何判斷S已經(jīng)完成遍歷
1 回答為啥報(bào)錯(cuò)呀
2 回答關(guān)于遍歷ArrayList
3 回答關(guān)于forEach遍歷
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-11-22
2018-11-22
構(gòu)造Student類的時(shí)候,需要進(jìn)行泛型
2018-11-05
沒(méi)泛型
2018-10-24
沒(méi)有導(dǎo)包