Call constructor with parameter inside Java stream with lambda

后端 未结 1 1520
[愿得一人]
[愿得一人] 2021-01-17 10:28

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 subSet(         


        
相关标签:
1条回答
  • 2021-01-17 10:53

    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)
    
    0 讨论(0)
提交回复
热议问题