Doubts about how the Cache in Guava “directly modifies the memory copy”?

  java, question

I just switched to JAVA and contacted Guava, so I may not have described the problem too clearly. Please forgive me.

Provided in GuavaCache module, the following example makes me very confused:

package me.kazaff;
 
 
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 
 import java.util.concurrent.TimeUnit;
 
 public class Main {
 
 public static LoadingCache<String, Person> cache = CacheBuilder.newBuilder()
 .maximumSize(1000)
 .expireAfterAccess(10, TimeUnit.MINUTES)
 .build(new CacheLoader<String, Person>() {
 @Override
 public Person load(String s) throws Exception {
 
 Person p = new Person();
 p.setName(s);
 p.setAge(0);
 return p;
 bracket
 });
 
 public static void main(String[] args) {
 try{
 
 Person p = cache.get("kazaff");
 p.setName("edisondik");  //directly modify the object
 
 Out.println ("object:" plus p.getName ()));
 Out.println ("cache:" add cache.get("kazaff").getName ());
 
 }catch (Exception e){
 System.out.println(e.getCause());
 bracket
 bracket
 bracket

Terminal printing:

Object: edisondik
 cache: edisondik

As you can see, I didn’t save the object back to the cache after modifying it. How did it do that?
It gives me the feeling that cache.get directly returns the reference!

Who can explain it to me?

This. . . What you get from cache inside is a reference to an object instance, always pointing to the same object instance.
The same is true for HashMap.

@Test
 public void dfasdf(){
 Map<String, Person> map = new HashMap<>();
 Person kazaff = new Person();
 kazaff.setName("kazaff");
 map.put("kazaff", kazaff);
 
 Person p = map.get("kazaff");
 p.setName("edisondik");
 System.out.println(map.get("kazaff").getName());  //get 'edisondik'
 bracket

Get the same instance twice from cache.

@Test
 public void mainTest() throws Exception {
 Person p = cache.get("kazaff");
 Person p1 = cache.get("kazaff");
 assertTrue(p == p1);  // success
 bracket