i am trying this in my copy constructor
protected int forca;
protected Spell []feitico;
public Picareta(final Picareta rValue)
{
super((Ferramenta)rValue);
this.forca=rValue.forca;
this.feitico=rValue.feitico.clone();
}
but feitico has the same references instead of cloning the objects in the array
do i really need to clone every element inside the array , or is my clone() for Spell wrong ?
public Spell clone() throws CloneNotSupportedException
{
super.clone();
Spell temp= new Spell(this);
return temp;
}
or is this way the best(compact) way to make it ?
public Picareta(final Picareta rValue)
{
super((Ferramenta)rValue);
this.forca=rValue.forca;
this.feitico=new Spell[rValue.feitico.length];
for (int i=0;i<rValue.feitico.length;i++)
this.feitico[i]=new Spell(rValue.feitico[i]);
}
clone()is useful at all, which...eh. (Generally speaking, best practice is to make pretty much everything immutable, in which case you never need to copy.)