Solved Easy cloning ?

Discussion in 'Plugin Development' started by Digi, Feb 28, 2013.

Thread Status:
Not open for further replies.
  1. I don't really get the implements Clonable thing, does that enable the class to be cloned properly ?

    I have alot of classes that can be added into a list, I need to clone that list and each individual element, is there any easy way without overwriting clone() for each class and copying its values manually ?

    The classes mostly contain Strings, Lists, ItemStacks and integers... some are empty.
     
  2. Well, it is enough to implement Cloneable if you are happy with what the default implementation of Object.clone() does. And that it's doing a first level copy, what means that the current object instance is copied and the field values of the new object will be the same as in the original object. So if a field of the original object references another object, the same field in the new object will reference the same object as it's value. If you want to have a deep copy, where the referenced objects are copied as well, you will need to overwrite clone() to get this done.
     
    NuclearW likes this.
  3. I see, I guess I've got to clone them individually, thanks :p
     
Thread Status:
Not open for further replies.

Share This Page