In my current problem, I have 2 objects whose type are known at runtime.
What I want to do is to replace the content of Object a with the content of Object b but I cannot do a = b; because there are other part of program that is holding a reference to Object a and it will require a lot of modification to update the reference. I looked into 2 possible solutions for this method.
1. I use reflection to iterate through Object a' fields and set each of them individually. However, Java access control is preventing me from setting the value of non-public fields.
2. Serialization: I read a couple of article but it only allow me to create a "new" instance of the same object not replacing the current content of an existing one.
add another level of indirection. instead of every class holding "a" directly, have a Holder class which holds the reference to "a" (and all the other classes have a reference to the Holder). then, when you update the holder, all the other objects will immediately see the new value.