Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186220

clarify semantics of Iterable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs

      The prevailing assumption about the Iterable interface is that such instances be independent of each other, that they not interfere with each other or with the underlying state of the implementing object, and that it be possible to create an arbitrary number of Iterators using successive calls to the iterator() method.

      However, the specification of Iterable is silent about all of these issues. While the semantics cannot be altered compatibly, a recommendation with the above could be added as an API note.

      The java.nio.file.DirectoryStream interface is a notable outlier here, as it implements Iterable but only one Iterator can be obtained from it. Since it's the outlier, it has a large warning to this effect.

            smarks Stuart Marks
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: