I know It might be already asked, but my question is something different. I've searched and I know java method object.clone() uses shallow copy which means copying references and not the actual objects. Let's say I have a dog Class
Class Dog{
public Dog(String name, DogTail tail, DogEar ear){
this.name = name;
this.tail = tail;
this.ear = ear;
}
}
DogTail t = new DogTail();
DogEar ear = new DogEar();
Dog dog1 = new Dog("good", t,ear);
let's say I want to get a copy of dog1.
Dog dognew = dog1.clone();
If this clone() method uses shallow copy, it means copying references. So If I change t object created above or ear method, it's gonna change in the dognew object or vice versa. How is this cloning good? This question was born because someone said that creating an big huge object is worse than cloning, as you save performance while using clone() method.