Java 8 filter with method call

I am learning lambda and Java 8 threads and trying on some examples. But he faces a problem. here is my code

fillUpdate(Person p){
    List<Address> notes = getAddress();
    notes.stream().filter( addr -> addr !=null).map( this::preparePersonInfo,p,addr);
}
private void preparePersonInfo(Person p, Address addr){
    // do some stuff
}

Gets a compilation error in the .map addr field (second argument). which is wrong, and could you provide links to learn java 8 threads. FYI follow this link Java 8 lambda

+4
source share
1 answer

The first problem is that the method call mapdoes not declare a variable addr.

The second problem is to use a method with no return type in map.

(map( this::preparePersonInfo,p,addr)), . preparePersonInfo Address, :

notes.stream().filter( addr -> addr !=null).forEach(this::preparePersonInfo);

Address .

, Stream, . preparePersonInfo , map ( map Stream - , - ). , forEach , , , - , .

preparePersonInfo :

notes.stream().filter( addr -> addr !=null).forEach (addr -> preparePersonInfo(p,addr));
+4
source

Source: https://habr.com/ru/post/1588940/


All Articles