Is it possible to create a method that can temporarily pause itself by "returning" and then resuming when it is called again? It should act as if it never returned (i.e. retain all its variables, continue executing the next line, etc.).
public static void main(String args) {
method(); //should start method
//do stuff ONLY AFTER method() RETURNS
method(); //should continue method at same place as it ended
//do more stuff ONLY AFTER method() RETURNS
}
private static void method() {
while(true) {
//do stuff
return;
//do different stuff
return;
//do a third thing
return;
//then start all over
}
}
I saw a few questions on StackOverflow that are similar, but none of the answers seemed sufficient or explanatory.