is there a way to update a class I am currently in with a new instance of that class?
For example:
public class Test
{
Test temp = new Test();
this = temp;
}
I am doing this because I have a save/load feature form serializable and I need a way to update the current class from it
No, Java variables store references to objects, so
this = ...will not work. There is no way for Java to track down every place that refers to the current instance ofTempand change the memory reference that they point to.The next-best thing may be to copy all of the fields from one object to another. That has its own set of problems, though.