The property of the object calls removeAll(), why did it delete itself

Tags: , ,



public static void main(String[] args) {

    Dto dto = new Dto();

    List<Long> aList = new ArrayList<>();
    aList.add(1L);
    aList.add(2L);
    aList.add(3L);
    dto.setIdList(aList);

    List<Long> bList = new ArrayList<>();
    bList.add(1L);
    bList.add(2L);

    List<Long> tempList = dto.getIdList();
    tempList.removeAll(bList);

    System.out.println(dto.getIdList());

}

@Data
public static class Dto{
    public List<Long> idList;
}

This code is a test method I wrote,the code in System.out.println(dto.getIdList());,the dto.getIdList() size is 1,and why not 3?why did it delete itself?

Answer

enter image description here

this is way to solve the problom



Source: stackoverflow