【发布时间】:2016-08-25 11:20:15
【问题描述】:
所以,我正在尝试更新我在 Java 6 发布时创建的旧 JavaFX 应用程序之一。我得到了一个提示,我可以转换当前代码并改用 lambda 表达式,有人可以帮我在这里转换这段代码或以某种方式指导我吗?
// define a simple boolean cell value for the action column so that the column will only be shown for non-empty rows.
addColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<UserDetails, Boolean>, ObservableValue<Boolean>>() {
@Override public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<UserDetails, Boolean> features) {
return new SimpleBooleanProperty(features.getValue() != null);
}
});
// create a cell value factory with an add button for each row in the table.
addColumn.setCellFactory(new Callback<TableColumn<UserDetails, Boolean>, TableCell<UserDetails, Boolean>>() {
@Override public TableCell<UserDetails, Boolean> call(TableColumn<UserDetails, Boolean> personBooleanTableColumn) {
return new AddPersonCell(window, tableUser);
}
});
【问题讨论】:
-
@DVarga,你可以不用最里面的花括号和
return关键字:addColumn.setCellValueFactory(features -> new SimpleBooleanProperty(features.getValue() != null));。 -
所有的人都非常擅长编程,我希望成为同样的人! :)
-
继续练习并继续提出与这个问题一样好的问题,你会的。我也只是在学习 lambdas。