如果我从HashMap中提取一个对象,然后修改它.它会在HashMap内修改吗?或者,我需要在修改后再将其设置回HashMap吗?
例如:
HashMap<Integer,TwoPoints> loc = new HashMap<Integer,TwoPoints>();
...
...
TwoPoints tp = loc.get(Id); //pulls out the object
tp.setPoint(group, new Point(x,y); //a method to set something inside the object I pulled.
Run Code Online (Sandbox Code Playgroud)
您将获得对实际对象的引用,因此任何更改都将反映在其中.您没有创建副本.
更新:
由于我使用术语"参考",我认为指出定义很重要.在Java的引擎下,事情并不像这样简单.但是引用(你正在做的)是获取指向对象的指针的值.
| 归档时间: |
|
| 查看次数: |
310 次 |
| 最近记录: |