I
Icarus
The idea is the following:
I have a program that, after is has run, restarts itself right from
the beginning. The problem is that many fields still have values from
the last go, especially in Singleton classes, and aren't properly
resetted. But I want to have the exact same situation as if the
program has just started. Resetting the fields manually is a truckload
of work and prone to errors.
So, the question is: is there a way for a Java program to exit and
restart itself, thus creating the same situation as on the first
start?
A small example:
public class SomeClass{
private String someField = "Just initialized";
public static void main(String args){
// Start the usual work of the program
this.start();
// Restart the program in a way that all fields are initialized
like they were on startup,
// WITHOUT manually setting all fields to their old values
this.restart();
}
private void start(){
System.out.println(this.someField );
this.someField = "Changed!";
}
}
How would the restart()-method have to look?
I have a program that, after is has run, restarts itself right from
the beginning. The problem is that many fields still have values from
the last go, especially in Singleton classes, and aren't properly
resetted. But I want to have the exact same situation as if the
program has just started. Resetting the fields manually is a truckload
of work and prone to errors.
So, the question is: is there a way for a Java program to exit and
restart itself, thus creating the same situation as on the first
start?
A small example:
public class SomeClass{
private String someField = "Just initialized";
public static void main(String args){
// Start the usual work of the program
this.start();
// Restart the program in a way that all fields are initialized
like they were on startup,
// WITHOUT manually setting all fields to their old values
this.restart();
}
private void start(){
System.out.println(this.someField );
this.someField = "Changed!";
}
}
How would the restart()-method have to look?