I’m getting an error, and can’t find out how to solve it.
I add a int to an ArrayList.
int n = 1;
ArrayList list = new ArrayList();
list.add( n );
Further down, I try to put it back in another int:
grid[ y ][ x ] = list.get(0);
I also tried this:
grid[ y ][ x ] = (int) list.get(0);
But it doesn’t work, I get this error:
found : java.lang.Object
required: int
grid[ y ][ x ] = (int)list.get(0);
^
I hope someone can help me.
Use a type parameter rather than the raw
ArrayList:The error you get is because you cannot cast an
Objecttoint, autoboxing breaks down there. You could cast it toIntegerand then have it autounboxed toint, but using the type parameter is a much better solution.