I have a byte array like this, that I do some operations on like increment and decrement.
byte[] cells = new byte[numCells]
....
....
cells[index]++;
Now, I want to change the type of the array cells based on some user input parameter to byte, short, int or long.
So, I made a new class Cell
public class Cell<T extends Number> {
T cell;
Cell(T defaultValue){
cell = defaultValue;
}
T get(){
return cell;
}
void set(T t){
cell = t;
}
}
And I am trying to use it like this
ArrayList<Cell<?>> cells;
if(cellSize == 8)
cells = new ArrayList<Cell<Byte>>(numCells);
else if(cellSize == 16)
cells = new ArrayList<Cell<Short>>(numCells);
...
...
The compiler throws the following error
error: incompatible types: ArrayList<Cell<Byte>> cannot be converted to ArrayList<Cell<?>>
cells = new ArrayList<Cell<Byte>>(numCells);
^
How can I accomplish this?