I have a HashSet of MyObject
that I need to clone. If MyObject
implements a copy-constructor, what is the easiest, neatest way to clone Set myObjects
Obviously I could do something like:
Set<MyObject> myNewObjects = new Set<MyObject>();
for(MyObject obj: myObjects) myNewObjects.add(new MyObject(obj));
But I'm doing this as part of a loooong copy-construcotr, and I'd really like to just be able to do it in one line like:
public myClass(MyClass toClone){
//...
this.myObjects = new Set<MyObjects>(toClone.getmyObjects());
//...
}
Any suggestions?