This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I need to do a deep copy of an object with both primative and String type variables. "clone" returns a copy with values for primatives and references for non-primative String ( I think). Is there an alternative to clone() that does deep, or can someone help me write an alternative.
You can override clone() with your own version with deep-copy semantics. Depending on the class, this might be as simple as calling super.clone() to get a shallow copy, and then calling clone() on each of your member objects, installing the copies inside your shallow copy, and then returning it.