第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么testForeach() 函數(shù)中 Course cr : student.courses 會(huì)報(bào)錯(cuò)?

package?com.imooc.stu;

import?java.util.ArrayList;
import?java.util.List;
import?java.util.*;

public?class?setTest?{

	public?List<Course>?coursetoSelect;
	
	public?setTest()?{
		this.coursetoSelect?=?new?ArrayList<Course>();	
	}

	public?void?crAdd(){
		
		Course[]?cr?=?{new?Course("1","語(yǔ)文"),new?Course("2","數(shù)學(xué)"),new?Course("3","英語(yǔ)"),new?Course("4","物理"),new?Course("5","生物")};
		
		coursetoSelect.addAll(Arrays.asList(cr));
		
	}
	
	
	public?void?crDisplay()?{
		
		System.out.println("有如下待選課程:");
		for(Course?cr:coursetoSelect)?{
			System.out.println(cr.id?+?"??"?+?cr.name);
		}
	}
	
	
	public?static?void?main(String[]?args)?{
		//?TODO?Auto-generated?method?stub
		
		setTest?st?=?new?setTest();
		st.crAdd();
		st.crDisplay();
		
		Student?student?=?new?Student("1","小明");
		System.out.println("歡迎學(xué)生:"?+?student.name);
		
		Scanner?sc?=?new?Scanner(System.in);
		
		for(int?i?=?0;i<3;i++){
			System.out.println("請(qǐng)輸入選擇課程ID:");
			String?scc?=?sc.next();
			for(Course?cr?:?st.coursetoSelect)?{
				if(cr.id.equals(scc))?{
					student.courses.add(cr);
					
				}
			}
				
			
		}
		
		st.testForeach(student);

	}
	
	public?void?testForeach(Student?student)?{
		for(Course?cr?:?student.courses){
			System.out.println(cr.id?+?""?+?cr.name);
		}
		
	}
	

}


正在回答

1 回答

package?com.imooc.stu;
import?java.util.*;

public?class?Student?{
???
	public?String?id;
	public?String?name;
	
	public?Set<Course>?courses;
	
	public?Student(String?id,?String?name)?{
		
		this.id?=?id;
		this.name?=?name;
		
		this.courses?=?new?HashSet<Course>();
		
	}
	
}

原來(lái)是Student類沒(méi)有定義泛型 ?public Set<Course> courses;

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么testForeach() 函數(shù)中 Course cr : student.courses 會(huì)報(bào)錯(cuò)?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)