About Question enthuware.ocpjp.ii.v11.2.3325 :

Moderator: admin

Post Reply
dongyingname
Posts: 18
Joined: Sat Jun 22, 2019 4:10 pm
Contact:

About Question enthuware.ocpjp.ii.v11.2.3325 :

Post by dongyingname » Wed Oct 23, 2019 1:48 pm

There is no correct answer, peek() only accept a Consumer as passed argument. getTitle() returns String not void, thus cannot be a Consumer.

admin
Site Admin
Posts: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3325 :

Post by admin » Wed Oct 23, 2019 9:04 pm

1. Did you try compiling and running it?
2. Recall from your OCA preparation that signature of a method does not include the return type.
If you like our products and services, please help us by posting your review here.

dongyingname
Posts: 18
Joined: Sat Jun 22, 2019 4:10 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3325 :

Post by dongyingname » Wed Oct 23, 2019 9:16 pm

I understood now.
The compiler doesn't see the return type of the lambda expression
as long as I don't write

Code: Select all

long count = bkStrm.peek(x -> {return x.getTitle();}).count();//doesn't compile

admin
Site Admin
Posts: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3325 :

Post by admin » Thu Oct 24, 2019 4:32 am

Well, bkStrm.peek(x -> {return x.getTitle();}).count(); would still be wrong and has nothing to do with the Consumer object that you are passing to the peek method. This statement doesn't compile because the method count() cannot be invoked on the type of the object returned by peek.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest