我想调用MySortedSet的构造函数,它将Comparator c作为参数。我该如何修改呢?
public MySortedSet<E> subSet(E fromElement, E toElement) {
return list.stream()
.filter(x -> (list.indexOf(x) <= list.indexOf(fromElement)
&& list.indexOf(x) < list.indexOf(toElement)))
.collect(Collectors.toCollection(MySortedSet<E> :: new));
}
答案 0 :(得分:22)
如果要将其他捕获的值作为参数传递,则无法使用方法引用。您将不得不使用lambda表达式:
MySortedSet<E> :: new
=&GT;
() -> new MySortedSet<E>(c)