0

What does "caputure<?>" mean in generics error messges? Consider following example:

interface Model<T> { T get(); }

static class DefaultModel<T> implements Model<T> {
    final T t;
    public DefaultModel(T t) { this.t = t; }
    @Override public T get() { return t; }
}

interface CellPopulator<T> {}

interface Column<T,S> extends CellPopulator<T> {}

static class Row {}

public static class Table<T,S> {
    public void updateCellItem(Model<Column<T,S>> model) {}
}

Types usage with unresolved conflict:

public static void main(String[] args) {
    Model<CellPopulator<Row>> gridCellModel = null;

    Table<Row,?> table = new Table<>();
    Column<Row,?> tableCell = (Column<Row, ?>) gridCellModel.get();
    Model<Column<Row,?>> tableCellModel = new DefaultModel<>(tableCell);

    // Model<Column<Row,capture<?>>> can not be applied to Model<Column<Row,?>>
    table.updateCellItem(tableCellModel); // COMPILATION ERROR
}
matoni
  • 2,479
  • 21
  • 39

0 Answers0