package com.hh;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Test03 {
    public static void main(String[] args) {
//        List<String> stringList= Collections.emptyList();
//        System.out.println(stringList.size());
//        List<Person> listPersons=new ArrayList();
//        Person person = new Person("1","1");
//        person.setPersonList(listPersons);
//        listPersons.add(new Person("2","2"));
//
//        System.out.println(person.getPersonList().size());

        Person person = new Person("1", "1");
        List<Person> personList=new ArrayList<Person>();
        List<Person> personList2=new ArrayList<Person>();
        person.setPersonList(personList2);
        Person person2 = new Person("3", "3");
        personList.add(person2);
        personList2=personList;
        System.out.println(personList2);
//        if(1==2){}
//        else {
//            personList2=personList;
//        }
        //personList2.addAll(personList);
        person.setPersonList(personList2);
        System.out.println(person);

    }
}

 一个对象引用另外一个对象,如果另外一个对象指向另外一个,然后那个原始空间的值没变

posted on 2021-01-06 19:05  王洪洪  阅读(281)  评论(0编辑  收藏  举报