Java - Cloneable

Hi, I’ve got some problems with the cloneable interface ::slight_smile:
Stucture:
ArrayList with custom graphic-objects;
graphic-object -> ArrayList with vectors + array with vectors + one lonely vector

Now I would like to clone this arrayList. Until now, I wrote my own clone() method (I just call the construc. of the object with the param. of the object to create a new object and return it).
ButI would like to use arraylist.clone(), therefore I have to implement the cloneable interface. Is it faster then creating a new object? Googled said, that it could fail.
How would you copy the arrayList?
Best regards

For a shallow copy: [icode]new ArrayList(oldArrayList)[/icode]. This works for any collection.

Chances are you don’t really want a deep copy. If you do, then there’s really no shortcut, you’ll have to do it by hand.

thx ;D

Mostly true, though Kryo can do deep copies (proper object->object too, not object->bytes->objects). :slight_smile: But often, especially with complex objects, you’ll just want to write copy constructors and do it by hand.