爲什麼我在我的代碼在我的課ArrayListTest最終得到一個編譯時錯誤兩種方法頭?的ArrayList在Java中,將代碼添加到方法
ArrayListTest:http://pastebin.com/dUHn9vPr
學生:http://pastebin.com/3Vz1Aytr
我有兩行編譯器錯誤:
delete(CS242, s3)
replace(CS242, s, s4);
當我嘗試運行代碼時指出:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method replace(ArrayList<Student>, Student, Student)in the type ArrayListTest is not applicable for the arguments (List<Student>, Student, Student)
The method delete(ArrayList<Student>, Student) in the type ArrayListTest is not applicable for the arguments (List<Student>, Student)
at ArrayListTest.main(ArrayListTest.java:54)
我修復了編譯時錯誤,因爲我使用Eclips e和Eclipse提供了可用於修復編譯時錯誤的代碼選項。我選擇了「將方法更改爲'(ArrayList,Student,Student)'替換爲'List(學生,學生)'
雖然它修復了編譯時錯誤,但我不明白爲什麼我得到編譯時錯誤開始,爲什麼能夠有效地固定錯誤
我真的不知道缺少什麼代碼,我需要寫更正以下兩種方法:
public static void replace(List<Student> cS242, Student oldItem,
Student newItem) {
public static void delete(List<Student> cS242, Student target){
這些錯誤是非常明顯的,方法聲明中的類型與您所調用的方法不匹配。 – Borgleader
閱讀泛型中的繼承。 – kosa
您應該在問題中包含ArrayListTest類的摘錄。由於pastebin內容是外部的,如果缺失可能會導致問題不合格。實際上它現在在23小時後過期。 – Javier