我从Java中的lambda表达式开始,我认为有些事情很奇怪,我确信我做错了或者有一个解决方法.
要定义比较器,我可以这样做:
col.setComparator((CustomCell o1, CustomCell o2) ->
((Comparable) o1.getValue()).compareTo(o2.getValue())
);
Run Code Online (Sandbox Code Playgroud)
但是,如果我只添加两个"{",那就太好了.我收到编译错误:
col.setComparator((CustomCell o1, CustomCell o2) -> {
((Comparable) o1.getValue()).compareTo(o2.getValue());
});
Run Code Online (Sandbox Code Playgroud)
该错误与"{"无关,但与setComparator:
The method setComparator(Comparator<CustomCell>) in the type
TableColumnBase<CustomParentCell,CustomCell> is not applicable for the arguments
((CustomCell o1, CustomCell o2) -> {})
Run Code Online (Sandbox Code Playgroud)
我之前尝试过使用多行语句来执行actionevents,它确实有效:
setOnAction(event -> {
// do something
});
Run Code Online (Sandbox Code Playgroud)
是因为它只有一个参数吗?