Need to process the table data during development and wrote the following code:
but found that after executing name.put, she clearly did not operate on the List object listname, but she had data, which led to subsequent logic errors (the breakpoint test diagram is at the end of the article)
Then use the following code to test:
public static void main(String[] args) {
List<Map> list = new ArrayList();
Map map = new HashMap();
list.add(map);
map.put("aa", 11);
map.put("bb", 11);
map.put("cc", 11);
list.forEach(m->System.out.println(m));
}
Output result:
After searching on the Internet, I found the reason:
In addition to the basic type of map, which is the value transfer of the eight classics, the rest are all reference address transfers.
Because the reference address transfer (list) stored in the value of the map occurs, when the internal properties of the list object occur When changing, the value in the map changes