Hi,
I am trying to do this:
public class BaseTable<T extends TableEntry>
{
protected int mRows;
protected int mCols;
protected ArrayList<T> mEntries;
public BaseTable(int rows, int cols)
{
mRows = rows;
mCols = cols;
mEntries = new ArrayList<T>();
for (int i = 0; i < rows; i++)
{
mEntries.add(new T(cols)); //this obv. doesn't work
}
}
}
Instantiating generics is hard enough as it is, but what makes this even harder is that T
here does not have a default constructor, it takes a single int
parameter in its constructor.
How can this be done?
I have asked a follow up question here too. I'd be grateful if you could answer that as well.
This question is related, but only is relevant where the classes are assumed to have a default constructor.