About Question enthuware.ocpjp.v8.2.1819 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

About Question enthuware.ocpjp.v8.2.1819 :

Post by __JJ__ »

Remember that Double objects are immutable. Therefore, the first call to forEach does not change the elements in the original list on which the stream is based. It only replaces the elements of that stream with new ones.
Hi Admin
Sorry, but isn't this an issue about java being pass by value? Isn't the argument that the lambda uses a copy of a reference, analogous to how references work when passed to, and inside of, a method such that if you do

Code: Select all

Integer i = 10;
foo(i);
and then inside foo:

Code: Select all

void foo(Integer i){
i=10;
}
isn't that exactly what's going on with the lambda, ie it's not got anything to do with immutability, and it is everything to do with the lambda getting a copy of a reference, just as foo does, and so when that reference is reassigned, it makes no difference to the original object, because the reassignment takes place on a copy-of-a-reference? This is why the StringBuilder is modified: because it's a copy of a reference AND the operation takes place on the object pointed to by the copy-of-the-reference.

Thank you in advance.

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

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

Post by admin »

Yes, that is correct. I have updated the explanation to make it clear.

thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

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

Post by __JJ__ »

OK thank you very much.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests