Yield Return In Java

后端 未结 10 1252
春和景丽
春和景丽 2020-12-13 23:13

I\'ve created a linked list in java using generics, and now I want to be able to iterate over all the elements in the list. In C# I would use yield return insid

10条回答
  •  情书的邮戳
    2020-12-13 23:42

    I don't understand why people are talking about threads... is there something I don't know about yield return?

    To my understanding yield return just saves the method stack and restores it at a later time. To implement yield return you just have to save the state manually. See the Java iterator classes for details, though for a linked list you can just get away with saving the current item. For an array you'd just need the index.

提交回复
热议问题