Quote:when I change that variable, it also changes the class attribute
Surprising, it shouldn't do that, not with the code you show.
Quote:I want to make a deep copy of an object to fit it into an array.
I don't understand what you try to do.
Showing a significant code fragment might help.
Quote:I think you just add "implements Cloneable" to your class declaration, and use object.clone() to get your copy.
Half true...
It will copy only primitive types, IIRC, and perhaps objects, but actually only their references: ie. if an object holds a reference to another, the cloned one will reference the same object.
The solution is to override clone(), or, better:
Quote:I usually just make a new object (object n = new object( oldObj.var1, oldObj.var2, etc) with the old object's variables.
That's not dirty, it is a recommended practice. Or, a slightly cleaner way is to use a copy constructor:
object n = new object(oldObject);That's less parameters to pass around...