小编Whe*_*hen的帖子

Why stream().map() can accept parameters like map(Student::getName)

This is the student class definition.

public class Student {
    public Student(String name) {
        this.name = name;
    }
    private String name;

    public String getName() {
        return name;
    }

}
Run Code Online (Sandbox Code Playgroud)

The map function should accept like a Function interface

<R> Stream<R> map(Function<? super T, ? extends R> mapper);
Run Code Online (Sandbox Code Playgroud)

That means the parameters should be like that

int func(int a){
    return b;
}
Run Code Online (Sandbox Code Playgroud)

We need to make sure have one method parameter. So why getName() can work? The method actually change to …

java java-8 java-stream

-5
推荐指数
1
解决办法
67
查看次数

标签 统计

java ×1

java-8 ×1

java-stream ×1