java - 泛型 - “捕获”不能应用于“?”
问题描述
泛型错误消息中的“”是什么caputure<?>
意思?考虑以下示例:
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) {}
}
类型使用与未解决的冲突:
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
}
解决方案
推荐阅读
- sql - 如何在 Oracle 过程 where 子句中使用 listagg 参数
- sql - 在 bigquery 中计算字符串中的不同字母
- python - 使用 Python 抓取足球结果时如何返回多个“得分手”?
- amazon-web-services - 用于停止 ec2 实例的 CUstom 警报
- node.js - ReferenceError:SharedArrayBuffer 未使用 React 和 MongoDB 定义
- node.js - 如何使用 fs.copyFileSync 通过 VPN 复制文件而不会出现未知错误?
- json - 无法在flutter中循环打印json服务器数据
- c - scala 本机垃圾收集器是否与 C 互操作性兼容?
- java - java - 如何在java spring mvc中将选择列表文本和值都从jsp传递到控制器?
- jenkins-pipeline - 如果 jenkins 声明性管道中的文件夹中有空间,如何获取工作空间?