0

Possible Duplicate:
Is there a Java equivalent to C#'s 'yield' keyword?

Does Java have Python style generators with the full call/yield (run/freeze) features of that Python feature?

http://www.python.org/dev/peps/pep-0255/

-- roschler

Community
  • 1
  • 1
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • @jleedev - Great link. But I don't know enough about C#'s yield/return implementation to know if it does everything that Python's does, as far as completely packing up the local context of the generator into a callable object. It's interesting. My first thought was, if Java didn't have generators, was trying to emulate generators using a cross-threaded approach, which is what the blog post linked to by your SO post talks about, with the help of a SynchronousQueue object for inter-thread communication: http://jimblackler.net/blog/?p=61 – Robert Oschler May 13 '11 at 04:53
  • 1
    How does "Java equivalent to C# feature" dupe "Java equivalent to Python feature"? Just because the C# and Python features may be similar, doesn't help this person if he doesn't know C#. Voted to reopen. – jscs May 13 '11 at 06:14
  • @Josh Casell: The answer is that there is no Java feature that does this, and that you should use the library referenced by the similar question about the C# feature which approximately simulates the feature in Java. – Omnifarious May 13 '11 at 07:31
  • It seems like someone tried to implement something like it base on multiple threads but this seems sub-optimal to me. https://gist.github.com/242100 – Christian K. Nov 01 '11 at 21:57

0 Answers0