I came across this problem while trying to iterate over columns of a JavaFX TableView. I want to call each column's cellFactory, so I did something like this -
for (TableColumn column : getTableView().getColumns()) {
column.getCellFactory().call(column);
}
Unfortunately, this doesn't work, as I get a compilation error:
incompatible types: javafx.scene.control.TableColumn< Model,capture#1 of ? > cannot be converted to javafx.scene.control.TableColumn< Model,capture#2 of ? >
How can I overcome this? Can I cast the parameter? Introduce explicit type-parameters?
The columns are naturally not all the same type, and I would very much like to avoid having to hard-code the type of every column, as this code should be used for various TableViews.
解决方案
You can drop the generics parameter and suppress the rawtypes warning
for (@SuppressWarnings("rawtypes") TableColumn column : getTableView().getColumns()) {
column.getCellFactory().call(column); // now compiles
}