A Generator, from the caller's perspective, looks like a normal iterator
that produces values. Because a standard iterator's next() method
must return every time, the programmer is forced to manage the stack
explicitly. The Generator class instead allows one to write a
task with an automatically managed stack and couple it to an
iterator interface.
For example:
class StringGenerator extends Generator{
public void execute() throws Pausable {
while (!done) {
String s = getNextWord(); // this can pause
yield(s);
}
}
private String getNextWord() throws Pausable {
}
}