【发布时间】:2014-11-26 13:34:41
【问题描述】:
我从 Java 中的 lambda 表达式开始,有些东西我认为很奇怪,我确信我做错了什么或者它有解决方法。
要定义一个比较器,我可以这样做:
col.setComparator((CustomCell o1, CustomCell o2) ->
((Comparable) o1.getValue()).compareTo(o2.getValue())
);
不过,如果我只添加两个“{”,那就太好了。我得到一个编译错误:
col.setComparator((CustomCell o1, CustomCell o2) -> {
((Comparable) o1.getValue()).compareTo(o2.getValue());
});
错误与“{”无关,而是与setComparator:
The method setComparator(Comparator<CustomCell>) in the type
TableColumnBase<CustomParentCell,CustomCell> is not applicable for the arguments
((CustomCell o1, CustomCell o2) -> {})
我之前尝试过将多行语句用于操作事件,它确实有效:
setOnAction(event -> {
// do something
});
是因为它只有一个参数吗?
【问题讨论】: