Search code examples
javacsetjmp

Is there a kind of setjmp/longjmp in java?


I admit, if it's possible, it would be open door to bad, very bad code... But in some specific cases...

So the question is, is there any equivalent of setjmp/longjmp ?

I would like to implement a python-like generator without using threads, just saving the stack and the context, and restore it later.


Solution

  • Simple answer: No there is not! The closest thing you can get are labeled breaks, which are a kind of forward jumps to break out of multiple nested blocks, but thats it!