Created
February 27, 2013 16:25
-
-
Save dlhartveld/5049226 to your computer and use it in GitHub Desktop.
Snippet from the JDK8 Collection interface demonstrating the addition of a default stream() method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Collection<E> extends Iterable<E> { | |
// Traditional, abstract methods: | |
int size(); | |
boolean contains(Object o); | |
boolean add(E e); | |
boolean remove(Object o); | |
// Etc... | |
// New methods stream() and parallelStream() with default implementations: | |
default Stream<E> stream() { | |
return Streams.stream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED), Spliterator.SIZED); | |
} | |
default Stream<E> parallelStream() { | |
return stream().parallel(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment