Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java 8 Streaming Filter & Collect return references to same objects in the list?

For example consider the code below

List<Reference> references = context.getReferences()
                                    .stream()
                                    .filter(ref -> ref.getCondition() == SOMETHING_DESIRABLE)
                                    .collect(Collectors.toList());

Now if I mutate each reference inside references list, will it be reflected inside the original context.references?

like image 399
Ace Avatar asked Aug 22 '17 22:08

Ace


1 Answers

There is no general way to clone objects in Java.

It would be fundamentally impossible for it to automatically return different instances.

like image 115
SLaks Avatar answered Sep 22 '22 11:09

SLaks