About Question enthuware.ocpjp.v8.2.1819 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dk35840
Posts: 4
Joined: Wed Jun 05, 2019 6:44 am
Contact:

About Question enthuware.ocpjp.v8.2.1819 :

Post by dk35840 »

HI Enthware,
We have remembered when we used curly braces we have to use return statement in lambda expression.

But here we don't use it.

dList.stream().forEach(x->{ x = x+10; });

Please help me.

dk35840
Posts: 4
Joined: Wed Jun 05, 2019 6:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1819 :

Post by dk35840 »

Here is screenshot from from OCA book ie OCA Oracle Certified Associate Java SE 8 Programmer 1 Study Guide" by Jeanne Boyarsky and Scott Selikoff
Attachments
enthware.jpg
enthware.jpg (30.8 KiB) Viewed 2777 times

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

Re: About Question enthuware.ocpjp.v8.2.1819 :

Post by admin »

Can't comment on what the book says, you should contact the author for that. But a return statement is required with {} if the functional method needs to return a value.

bvrulez
Posts: 33
Joined: Sat Feb 15, 2020 12:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1819 :

Post by bvrulez »

I also was confused by the missing return type and that's how I did not grasp the more interesting concept of passing by values if the object is immutable. I am writing it to remember better. :) The return type is not necessary, because forEach() uses a consumer and a consumer returns void. It would probably also be a compiler error to add a return statement. I am such a Pro!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 12 guests