Page 1 of 1

About Question enthuware.ocpjp.v8.2.1819 :

Posted: Wed Sep 25, 2019 10:56 am
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.

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

Posted: Wed Sep 25, 2019 11:31 am
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

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

Posted: Wed Sep 25, 2019 6:08 pm
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.

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

Posted: Wed Feb 19, 2020 7:09 am
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!