我忙于制作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