" do in Java? I looked at several java tutorials and was not sure what the "->" did and could not find anything on Google about this. ...">

What does "->" do in Java?

I looked at several java tutorials and was not sure what the "->" did and could not find anything on Google about this.

Here is the code I saw that used it:

myShapesCollection.stream() .filter(e -> e.getColor() == Color.RED) .forEach(e -> System.out.println(e.getName())); 
+7
java java-8
Dec 25 '13 at 9:56
source share
1 answer

This is the syntax used for lambda expressions available in Java 8.

For example, filter expects Predicate and e -> e.getColor() == Color.RED functionally equivalent:

 new Predicate<Shape>() { public boolean test(Shape s) { return s.getColor() == Color.RED; } } 
+21
Dec 25 '13 at 9:58
source share



All Articles