Java. :
MyObj first = new MyObj(someOwner, someTag, someInt);
MyObj second = first;
( ) . MyObj. , clone(), - , . , , : clone , - , . , :
MyObj third = (MyObj) first.clone();
clone() first / MyObj. , - , .
: - . MyObj, , Person NameTag. MyObj, , , , NameTag (, , ). - MyObj NameTag "--" "" "MyObj". , :
class MyObj implements Cloneable {
private Person owner;
private NameTag tag;
private int size;
public MyObj(Person owner, NameTag tag, int size) {
this.owner = owner;
this.tag = tag;
this.size = size;
}
public Object clone() {
MyObj result;
try {
result = (MyObj) super.clone();
}
catch (CloneNotSupportedException e) {
throw new RuntimeException
("Super class doesn't implement cloneable");
}
result.owner = owner;
result.tag = tag.clone()
result.size = size;
return result;
}