None of this codes will compile. I would like to understand why and how I could solve this. This is simplified and the method-signature is given by a framework. I would like to offer a default that can be overwritten with subtypes of 'TableItem'.
Error at add
:
public <TI extends TableItem> ArrayList<TI> getTable() {
ArrayList<TI> list = new ArrayList<TI>();
TableItem item = new TableItem();
list.add(item);
return list;
}
Error at return
:
public <TI extends TableItem> ArrayList<TI> getTable() {
ArrayList<TableItem> list = new ArrayList<TableItem>();
TableItem item = new TableItem();
list.add(item);
return list;
}
Edit:
This helped me a bit: Difference between <? super T> and <? extends T> in Java