Is it possible to set the default behavior of my Java project (or some subset of it) to make copies of my objects when I pass them into methods or functions?
The reason for wanting this behavior is that I am writing a number of tests that check that two functions produce the same return. If I pass in ObjectA
(where a property count is initialized to 3) to function decrementCount()
than when it returns the object I will see (ObjectA.count -> 2)
, while after calling the second function the object is now (ObjectA.count -> 1)
.
I would like to achieve pass-by-value rather than pass-by-reference.