上Java基础的一些问题, 以下函数返回节点类型的对象预先返回的对象修改的java
class DS{
public Node getNode(int index){
return nodeList.get(index);
}
}
public void test1(){
DS ds = new DS();
Node node = ds.getNode(3);
// will the change in node variable(of test1()) change the actual Node object in ds?
// Is there a simple way to create a copy to prevent source node's data modification?
}
感谢。
仅供参考,接受同一类型的另一个对象,并创建一个副本从它(不出所料)“拷贝给一个构造函数的名称构造函数“ – Bohemian 2012-03-29 01:35:59
现有的默认克隆方法不够吗? 我应该明确实施吗? – sravanreddy001 2012-03-29 01:39:32
@mrb - 如果你在一个没有实现'Cloneable'的对象上调用clone(),你会得到一个'CloneNotSupportedException'。参考:用于'Cloneable'的javadocs。 – 2012-03-29 01:46:48