I want to call a constructor for MySortedSet that takes in a Comparator c as a parameter. How can I modify this to do so?
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));
}
You can’t use method references if you want to pass additional captured values as parameters. You will have to use a lambda expression instead:
MySortedSet<E> :: new
=>
() -> new MySortedSet<E>(c)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With