The problem with creating deep copies is that everything that is not a primitive type is copied by reference, unless you also use a specific deep copy constructor on it.
In your particular case, you have no problem with variable bool , int or a String , because you pass them by value (in fact, String is passed by reference, but it is not changed, so there is no problem), but you pass ArrayList<Question> questionList . When you do
this.object = incoming.object
you just copy the link. Thus, both variables point to the same object in memory , so you are not deep copying it. You must create another instance of the object with the same internal values, then you will be sure, for example this.object = new YourObject(incoming.object) .
The mind, which usually means that your class is more complicated in the composition tree, you will need to go into variables more until you copy them.
source share