[英]Passing Class.forName through generic type class parameter
I am trying to make universal TableView in JavaFx for all of my models in application: 我试图在JavaFx中为应用程序中的所有模型制作通用TableView:
Class c = Class.forName(fullClassNames.get(itemNum));
table.getItems().clear();
Field[] fields = c.getDeclaredFields();
for (int i=0; i < fields.length; i++){
table.getColumns().add(new TableColumn(fields[i].getName()));
((TableColumn)table.getColumns().get(table.getColumns().size()-1)).setCellValueFactory(new PropertyValueFactory<???, ???>(fields[i].getName()));
}
and I don't know how can I pass "c" (that stores my model) and field type through PropertyValueFactory like generic parameter? 而且我不知道如何通过PropertyValueFactory像通用参数一样传递“ c”(存储我的模型)和字段类型? For example it looks like: 例如,它看起来像:
new PropertyValueFactory<Person,String>("lastName")
Generics are largely a compile time feature. 泛型在很大程度上是编译时功能。
You don't have to specify the generic types at run time. 您不必在运行时指定泛型类型。
You can create 您可以创建
new PropertyValueFactory("lastName")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.