I was looking at some java tutorials and wasn't sure what '->' did and couldn't find anything on google about it.
Here's some code that I saw that used it:
myShapesCollection.stream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));
That is the syntax used for lambda expressions, available in Java 8.
For example, filter
expects a Predicate
and e -> e.getColor() == Color.RED
is functionally equivalent to:
new Predicate<Shape>() {
public boolean test(Shape s) { return s.getColor() == Color.RED; }
}
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