什么是'-&燃气轮机';你喜欢Java吗?

什么是'-&燃气轮机';你喜欢Java吗?,java,java-8,Java,Java 8,我在看一些java教程,不确定“->”做了什么,在google上找不到任何关于它的内容 下面是我看到的一些使用它的代码: myShapesCollection.stream() .filter(e -> e.getColor() == Color.RED) .forEach(e -> System.out.println(e.getName())); 这是Java 8中使用的语法 例如,filter需要一个谓词,而e->e.getColor()==Color.RED在功能上等同于:

我在看一些java教程,不确定“->”做了什么,在google上找不到任何关于它的内容

下面是我看到的一些使用它的代码:

myShapesCollection.stream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));

这是Java 8中使用的语法

例如,
filter
需要一个
谓词,而
e->e.getColor()==Color.RED
在功能上等同于:

new Predicate<Shape>() {
    public boolean test(Shape s) { return s.getColor() == Color.RED; }
}
new谓词(){
公共布尔测试(形状s){返回s.getColor()==Color.RED;}
}

这是Java 8+1中的一个特性,即编写语法,我认为等价的代码应该是
new Predicate(){public boolean test(Shape e){return e.getColor()==Color.RED;}}
。确实如此。非常感谢。