JavaFX将问号表视图转换为已知类型
我在向TableView插入元素时遇到问题 我从节点获取了tableview的引用。问题是我在向表中插入元素时出错JavaFX将问号表视图转换为已知类型,java,generics,javafx,tableview,Java,Generics,Javafx,Tableview,我在向TableView插入元素时遇到问题 我从节点获取了tableview的引用。问题是我在向表中插入元素时出错 类型列表中的add(capture#2-of?)方法不适用于参数 TableView<?> table = (TableView<?>)mainPane.getChildren().stream().filter(c -> c instanceof TableView<?>).findFirst().get(); ControlTimeP
类型列表中的add(capture#2-of?)方法不适用于参数
TableView<?> table = (TableView<?>)mainPane.getChildren().stream().filter(c -> c instanceof TableView<?>).findFirst().get();
ControlTimePickerController ctpc = new ControlTimePickerController();
if (ctpc.exitedWithButton()) {
ControlSchedule cSch = ctpc.getSelectedControlSchedule();
//I'M GETTING THE ERROR HERE
table.getItems().add(cSch);
}
TableView table=(TableView)主窗格.getChildren().stream().filter(c->c instanceof TableView.findFirst().get();
ControlTimePickerController ctpc=新ControlTimePickerController();
如果(ctpc.exitedWithButton()){
ControlSchedule cSch=ctpc.getSelectedControlSchedule();
//我在这里得到了错误
table.getItems().add(cSch);
}
您需要使用另一个类型参数,指示ControlSchedule
确实是一个可以添加到项目列表或使用原始类型的类型。在这种情况下,后一种方法与使用TableView
的效果类似。但是,不鼓励使用原始类型;在本例中,您已经将类型安全设置抛出了窗口
在这里,我建议使用
TableView<? super ControlSchedule> table = (TableView<? super ControlSchedule>)mainPane.getChildren().stream().filter(c -> c instanceof TableView<?>).findFirst().get();
TableView您需要使用另一个类型参数,指示ControlSchedule
确实是一个可以添加到项目列表或使用原始类型的类型。在这种情况下,后一种方法与使用TableView
的效果类似。但是,不鼓励使用原始类型;在本例中,您已经将类型安全设置抛出了窗口
在这里,我建议使用
TableView<? super ControlSchedule> table = (TableView<? super ControlSchedule>)mainPane.getChildren().stream().filter(c -> c instanceof TableView<?>).findFirst().get();
tableview此示例不完整。mainPane.getChildren()的返回类型是什么?请先发布一个最小的、可复制的样本:此示例不完整。mainPane.getChildren()的返回类型是什么?请先发布一个最小的、可复制的样品: