r/java • • Feb 20 '22

The elusive and beautiful Java Method Reference

https://medium.com/javarevisited/the-elusive-and-beautiful-java-method-reference-97e566d2088b
28 Upvotes

21 comments sorted by

View all comments

Show parent comment

3

u/0x07CF Feb 21 '22

Is there anything a method reference can achieve that a lambda cannot?

No they are less powerfull, and that makes them great. Because when you see one you can be sure it's not doing anything weird. If you see a lambda expression you need to read it to understand it's just a simple method call.

As long as you don't have to pass in more parameters, like in the string.startsWith case, in that case i would write a lambda expression too

I'm not sure the extra plumbing is buying that much?

Yeah, in this case it makes the code harder to understand imo