Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    This doesn't answer the question. Your two alternatives are only cosmetically different. I think the OP is talking about defensive copying, so that if MyOtherClass is mutable, the client code cannot pass it to an instance of MyClass (either with a setter or the constructor, like in your example), and then mutate outside said instance. Commented Apr 6, 2016 at 23:24
  • (I agree that clone is generally broken, which is why Effective Java recommends not using it). Commented Apr 6, 2016 at 23:26
  • 1
    -1. As Andres said, it misses the point of the question. Commented Apr 7, 2016 at 2:31