Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 8
    I see, first of all, thanks a lot for answering the question. I am still curious though why an Iterable<Integer> (I think you are talking about?) would want to return an IntStream. Would the iterable then not rather be a PrimitiveIterator.OfInt? Or do you perhaps mean another usecase? Commented Apr 20, 2014 at 10:26
  • 157
    I find it odd that the above logic was supposedly applied to Iterable (I can't have stream() because someone might want it to return IntStream) whereas an equal amount of thought wasn't given to adding the exact same method to Collection (I might want my Collection<Integer>'s stream() to return IntStream also.) Whether it were present on both or absent on both, people would probably have just gotten on with their lives, but because it's present on one and absent on the other, it becomes quite a glaring omission... Commented Jan 27, 2015 at 5:33
  • 7
    Why couldn't Iterable have stream(), then implementors can add intStream() if applicable? Also, I suspect the cases where the issue you describe would occur are rare. Commented Jun 24, 2016 at 1:28
  • 69
    While this makes sense, is there a reason why there isn't an alternative static Stream.of(Iterable), which would at least make the method reasonably discoverable by reading the API documentation -- as somebody who has never really worked with the internals of Streams I'd never even looked at StreamSupport, which is described in the documentation as providing "low-level operations" that are "mostly for library writers". Commented Jul 30, 2016 at 10:39
  • 19
    I totally agree with Jules. a static method Stream.of(Iteratable iter) or Stream.of(Iterator iter) should be added, instead of StreamSupport.stream(iter.spliterator(), false); Commented Dec 2, 2016 at 22:56