Map SourceAsMap=ESUnit. GetSourceAsMap (searchHit searchMethod, searchField, searchFieldTwo); String authorObjectName=sourceAsMap. Get (" AuthorObjectJson. The Name ")==null?" ": sourceAsMap. Get (" AuthorObjectJson. The Name"). The toString (); List
Perform such a piece of code, I inside the for loop using the map. The put (" Name ", authorObjectName); Change the map object that current traversal, why authorObjectJson this object also follow change, the most magical is why sourceAsMap value also follow changes inside the object?
CodePudding user response:
You traverse map object is not traverse authorObjectJson object? Traversed you modify the content, of course authorObjectJson will change, and authorObjectJson is sourceAsMap values, sourceAsMap change is yes Note whether you use sourceAsMap. Get (key) or for loop, you are to get the object reference address, you to modify the address corresponding to the content, before must have been a reference to the revision
CodePudding user response:
You need to understand the first programming language in the "reference" and "value transfer" these two concepts, In simple terms, reference is the object itself, value transfer is the passed object "copy",