Search code examples
javaconstructorcascading

Why it's not a good idea to hold an instance with out first copying it via its copy constructor?


I was trying to understand Cascading. So I started reading the documentation and found this line, "Since Tuples are mutable, it is not a good idea to hold an instance around with out first copying it via its copy constructor, a subsequent Pipe could change the Tuple in place. " I don't know what it means? Why it's not a good idea to hold an instance with out first copying it via its copy constructor? Would like to see some examples? Thank you...


Solution

  • It just means that the values in the Tuple that you're holding can change unexpectedly because of something that happens in a subsequent Pipe. But if you copy the Tuple using its copy constructor, and then hold on to the new instance, then you have the only copy and nothing else can change it.