我忙於製作Java遊戲,對於敵人,我將它們存儲在ArrayList
中。但是當我嘗試使用get(int)
方法時,它一直給我The type of get(int) is erroneous where E is a type-variable:
這是爲什麼?它不應該只是返回元素?我搜索了一段時間,一直沒能找到解決辦法。不斷收到一個ArrayList的get()錯誤。爲什麼?
這裏是我的代碼的一部分:
for(int i=0;i<holes.size();i++){
hole temp = holes.get(i);
if((p1.playerRec.x/48)==(temp.holeRec.x/48) && (p1.playerRec.y/48)==(temp.holeRec.y/48)){
gameOver=true;
}
}
public void findHoles(){
for(int i=0;i<map1.height;i++){
for(int j=0;j<map1.width;j++){
if(map1.tileMap[i][j]==5){
addHole(new hole(i,j));
}
}
}
}
public void addHole(hole h){
holes.add(h);
}
也許有些代碼會讓我們開心! – DGomez 2013-04-27 01:24:16
您可能應該閱讀[generic types](http://docs.oracle.com/javase/tutorial/java/generics/why.html)。 – Pshemo 2013-04-27 01:24:33
我猜是因爲你把它分配給不同類型的變量:p – cakil 2013-04-27 01:27:27