Return method reference

后端 未结 2 1154
谎友^
谎友^ 2021-01-15 20:06

I am playing around in Java 8. How can I return a method reference?

I am able to return a lambda but not the method reference.

My attempts:

p         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-15 20:31

    I would like to add some points.

    You can't instantiate unbounded type instance.

    List list = new ArrayList();
    

    Second, as Tunaki mentioned, you can't make references to new MyObject::staticMethod when you make method references

    The other thing is, forEach(Consumer consumer) (Terminal operation for pipeline streams) doesn't return anything. It only eats whatever we feed it.

    -Hope this may help :)

提交回复
热议问题